summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-28 00:45:10 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-28 00:45:10 +0000
commit08a2bfd230cfc8049b6015c7ca2a3cc7d2fadb2f (patch)
tree283e9aa2b4ae63f090f71cd664d7af9daa212b64 /clang/lib/Frontend/CompilerInstance.cpp
parentb7098a38b39758316d78c1a16f57227c5d2064ac (diff)
downloadbcm5719-llvm-08a2bfd230cfc8049b6015c7ca2a3cc7d2fadb2f.tar.gz
bcm5719-llvm-08a2bfd230cfc8049b6015c7ca2a3cc7d2fadb2f.zip
Cut down the number of open/close system calls for output files.
For PCH files, have only one open/close for temporary + rename to be safe from race conditions. For all other output files open/close the output file directly. Depends on llvm r136310. rdar://9082880 & http://llvm.org/PR9374. llvm-svn: 136315
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index ef0796ab01c..026cb5a3d51 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -437,11 +437,13 @@ llvm::raw_fd_ostream *
CompilerInstance::createOutputFile(StringRef OutputPath,
bool Binary, bool RemoveFileOnSignal,
StringRef InFile,
- StringRef Extension) {
+ StringRef Extension,
+ bool UseTemporary) {
std::string Error, OutputPathName, TempPathName;
llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
RemoveFileOnSignal,
InFile, Extension,
+ UseTemporary,
&OutputPathName,
&TempPathName);
if (!OS) {
@@ -465,6 +467,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
bool RemoveFileOnSignal,
StringRef InFile,
StringRef Extension,
+ bool UseTemporary,
std::string *ResultPathName,
std::string *TempPathName) {
std::string OutFile, TempFile;
@@ -480,8 +483,11 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
} else {
OutFile = "-";
}
-
- if (OutFile != "-") {
+
+ llvm::OwningPtr<llvm::raw_fd_ostream> OS;
+ std::string OSFile;
+
+ if (UseTemporary && OutFile != "-") {
llvm::sys::Path OutPath(OutFile);
// Only create the temporary if we can actually write to OutPath, otherwise
// we want to fail early.
@@ -489,21 +495,26 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
if ((llvm::sys::fs::exists(OutPath.str(), Exists) || !Exists) ||
(OutPath.isRegularFile() && OutPath.canWrite())) {
// Create a temporary file.
- llvm::sys::Path TempPath(OutFile);
- if (!TempPath.makeUnique(/*reuse_current=*/false, /*ErrMsg*/0))
- TempFile = TempPath.str();
+ llvm::SmallString<128> TempPath;
+ TempPath = OutFile;
+ TempPath += "-%%%%%%%%";
+ int fd;
+ if (llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath,
+ /*makeAbsolute=*/false) == llvm::errc::success) {
+ OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
+ OSFile = TempFile = TempPath.str();
+ }
}
}
- std::string OSFile = OutFile;
- if (!TempFile.empty())
- OSFile = TempFile;
-
- llvm::OwningPtr<llvm::raw_fd_ostream> OS(
- new llvm::raw_fd_ostream(OSFile.c_str(), Error,
- (Binary ? llvm::raw_fd_ostream::F_Binary : 0)));
- if (!Error.empty())
- return 0;
+ if (!OS) {
+ OSFile = OutFile;
+ OS.reset(
+ new llvm::raw_fd_ostream(OSFile.c_str(), Error,
+ (Binary ? llvm::raw_fd_ostream::F_Binary : 0)));
+ if (!Error.empty())
+ return 0;
+ }
// Make sure the out stream file gets removed if we crash.
if (RemoveFileOnSignal)
OpenPOWER on IntegriCloud