From 1276b396130a0cdbbb8e6c05a6e43123df18ed60 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 5 Jul 2013 20:14:52 +0000 Subject: [PATCH] Use sys::fs::createTemporaryFile. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185719 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/GraphWriter.cpp | 3 +-- lib/Transforms/Instrumentation/DebugIR.cpp | 3 +-- tools/bugpoint/Miscompilation.cpp | 16 ++++++++-------- tools/bugpoint/ToolRunner.cpp | 4 ++-- tools/lto/LTOCodeGenerator.cpp | 3 +-- unittests/Support/Path.cpp | 14 +++++++------- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/lib/Support/GraphWriter.cpp b/lib/Support/GraphWriter.cpp index 20214c71d6b..64d21642e8e 100644 --- a/lib/Support/GraphWriter.cpp +++ b/lib/Support/GraphWriter.cpp @@ -68,8 +68,7 @@ StringRef llvm::DOT::getColorString(unsigned ColorNumber) { std::string llvm::createGraphFilename(const Twine &Name, int &FD) { FD = -1; SmallString<128> Filename; - error_code EC = sys::fs::unique_file(Twine(Name) + "-%%%%%%%.dot", - FD, Filename); + error_code EC = sys::fs::createTemporaryFile(Name, "dot", FD, Filename); if (EC) { errs() << "Error: " << EC.message() << "\n"; return ""; diff --git a/lib/Transforms/Instrumentation/DebugIR.cpp b/lib/Transforms/Instrumentation/DebugIR.cpp index f4109eff4f5..b5bdc7560b6 100644 --- a/lib/Transforms/Instrumentation/DebugIR.cpp +++ b/lib/Transforms/Instrumentation/DebugIR.cpp @@ -504,10 +504,9 @@ bool DebugIR::updateExtension(StringRef NewExtension) { } void DebugIR::generateFilename(OwningPtr &fd) { - StringRef FileModel("debug-ir-%s%s%s%s.ll"); SmallVector PathVec; fd.reset(new int); - sys::fs::unique_file(FileModel, *fd, PathVec); + sys::fs::createTemporaryFile("debug-ir", "ll", *fd, PathVec); StringRef Path(PathVec.data(), PathVec.size()); Filename = sys::path::filename(Path); sys::path::remove_filename(PathVec); diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 73b5cd1fe84..5574303321c 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -928,8 +928,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, SmallString<128> TestModuleBC; int TestModuleFD; - error_code EC = sys::fs::unique_file("bugpoint.test-%%%%%%%.bc", TestModuleFD, - TestModuleBC); + error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", + TestModuleFD, TestModuleBC); if (EC) { errs() << BD.getToolName() << "Error making unique filename: " << EC.message() << "\n"; @@ -947,8 +947,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, // Make the shared library SmallString<128> SafeModuleBC; int SafeModuleFD; - EC = sys::fs::unique_file("bugpoint.safe-%%%%%%%.bc", SafeModuleFD, - SafeModuleBC); + EC = sys::fs::createTemporaryFile("bugpoint.safe", "bc", SafeModuleFD, + SafeModuleBC); if (EC) { errs() << BD.getToolName() << "Error making unique filename: " << EC.message() << "\n"; @@ -1022,8 +1022,8 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { SmallString<128> TestModuleBC; int TestModuleFD; - error_code EC = sys::fs::unique_file("bugpoint.test-%%%%%%%.bc", TestModuleFD, - TestModuleBC); + error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc", + TestModuleFD, TestModuleBC); if (EC) { errs() << getToolName() << "Error making unique filename: " << EC.message() << "\n"; @@ -1040,8 +1040,8 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { // Make the shared library SmallString<128> SafeModuleBC; int SafeModuleFD; - EC = sys::fs::unique_file("bugpoint.safe-%%%%%%%.bc", SafeModuleFD, - SafeModuleBC); + EC = sys::fs::createTemporaryFile("bugpoint.safe", "bc", SafeModuleFD, + SafeModuleBC); if (EC) { errs() << getToolName() << "Error making unique filename: " << EC.message() << "\n"; diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index a9a4a9d27f1..bec00364d7c 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -141,8 +141,8 @@ static std::string ProcessFailure(StringRef ProgPath, const char** Args, // Rerun the compiler, capturing any error messages to print them. SmallString<128> ErrorFilename; int ErrorFD; - error_code EC = sys::fs::unique_file("bugpoint.program_error_messages", - ErrorFD, ErrorFilename); + error_code EC = sys::fs::createTemporaryFile( + "bugpoint.program_error_messages", "", ErrorFD, ErrorFilename); if (EC) { errs() << "Error making unique filename: " << EC.message() << "\n"; exit(1); diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 88f2a0f27e9..022a04c178e 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -162,8 +162,7 @@ bool LTOCodeGenerator::compile_to_file(const char** name, std::string& errMsg) { // make unique temp .o file to put generated object file SmallString<128> Filename; int FD; - error_code EC = sys::fs::unique_file("lto-llvm-%%%%%%%.o", - FD, Filename); + error_code EC = sys::fs::createTemporaryFile("lto-llvm", "o", FD, Filename); if (EC) { errMsg = EC.message(); return true; diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index ce335ccc6b1..4fc02be5e3a 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -165,7 +165,7 @@ TEST_F(FileSystemTest, Unique) { int FileDescriptor; SmallString<64> TempPath; ASSERT_NO_ERROR( - fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath)); + fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); // The same file should return an identical unique id. uint64_t F1, F2; @@ -177,8 +177,8 @@ TEST_F(FileSystemTest, Unique) { int FileDescriptor2; SmallString<64> TempPath2; ASSERT_NO_ERROR( - fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor2, TempPath2)); - + fs::createTemporaryFile("prefix", "temp", FileDescriptor2, TempPath2)); + uint64_t D; ASSERT_NO_ERROR(fs::getUniqueID(Twine(TempPath2), D)); ASSERT_NE(D, F1); @@ -201,7 +201,7 @@ TEST_F(FileSystemTest, TempFiles) { int FileDescriptor; SmallString<64> TempPath; ASSERT_NO_ERROR( - fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath)); + fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); // Make sure it exists. bool TempFileExists; @@ -211,7 +211,7 @@ TEST_F(FileSystemTest, TempFiles) { // Create another temp tile. int FD2; SmallString<64> TempPath2; - ASSERT_NO_ERROR(fs::unique_file("%%-%%-%%-%%.temp", FD2, TempPath2)); + ASSERT_NO_ERROR(fs::createTemporaryFile("prefix", "temp", FD2, TempPath2)); ASSERT_NE(TempPath.str(), TempPath2.str()); fs::file_status A, B; @@ -369,7 +369,7 @@ TEST_F(FileSystemTest, Permissions) { int FileDescriptor; SmallString<64> TempPath; ASSERT_NO_ERROR( - fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath)); + fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); // Mark file as read-only const fs::perms AllWrite = fs::owner_write|fs::group_write|fs::others_write; @@ -396,7 +396,7 @@ TEST_F(FileSystemTest, FileMapping) { int FileDescriptor; SmallString<64> TempPath; ASSERT_NO_ERROR( - fs::unique_file("%%-%%-%%-%%.temp", FileDescriptor, TempPath)); + fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath)); // Map in temp file and add some content error_code EC; StringRef Val("hello there"); -- 2.34.1