summaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp41
1 files changed, 16 insertions, 25 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp b/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp
index 276a9676eaa9..0e5a8e504dc5 100644
--- a/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -12,6 +12,7 @@
#include "clang/Frontend/PrecompiledPreamble.h"
#include "clang/AST/DeclObjC.h"
+#include "clang/Basic/LangStandard.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
@@ -26,11 +27,10 @@
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Mutex.h"
-#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <limits>
+#include <mutex>
#include <utility>
using namespace clang;
@@ -95,7 +95,7 @@ public:
void removeFile(StringRef File);
private:
- llvm::sys::SmartMutex<false> Mutex;
+ std::mutex Mutex;
llvm::StringSet<> Files;
};
@@ -105,20 +105,20 @@ TemporaryFiles &TemporaryFiles::getInstance() {
}
TemporaryFiles::~TemporaryFiles() {
- llvm::MutexGuard Guard(Mutex);
+ std::lock_guard<std::mutex> Guard(Mutex);
for (const auto &File : Files)
llvm::sys::fs::remove(File.getKey());
}
void TemporaryFiles::addFile(StringRef File) {
- llvm::MutexGuard Guard(Mutex);
+ std::lock_guard<std::mutex> Guard(Mutex);
auto IsInserted = Files.insert(File).second;
(void)IsInserted;
assert(IsInserted && "File has already been added");
}
void TemporaryFiles::removeFile(StringRef File) {
- llvm::MutexGuard Guard(Mutex);
+ std::lock_guard<std::mutex> Guard(Mutex);
auto WasPresent = Files.erase(File);
(void)WasPresent;
assert(WasPresent && "File was not tracked");
@@ -202,7 +202,7 @@ PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI,
std::unique_ptr<llvm::raw_ostream> OS;
if (InMemStorage) {
- OS = llvm::make_unique<llvm::raw_string_ostream>(*InMemStorage);
+ OS = std::make_unique<llvm::raw_string_ostream>(*InMemStorage);
} else {
std::string OutputFile;
OS = GeneratePCHAction::CreateOutputFile(CI, InFile, OutputFile);
@@ -213,7 +213,7 @@ PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI,
if (!CI.getFrontendOpts().RelocatablePCH)
Sysroot.clear();
- return llvm::make_unique<PrecompilePreambleConsumer>(
+ return std::make_unique<PrecompilePreambleConsumer>(
*this, CI.getPreprocessor(), CI.getModuleCache(), Sysroot, std::move(OS));
}
@@ -303,7 +303,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
Clang->getFrontendOpts().Inputs[0].getKind().getFormat() !=
InputKind::Source ||
Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() ==
- InputKind::LLVM_IR) {
+ Language::LLVM_IR) {
return BuildPreambleError::BadInputs;
}
@@ -369,9 +369,11 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
SourceManager &SourceMgr = Clang->getSourceManager();
for (auto &Filename : PreambleDepCollector->getDependencies()) {
- const FileEntry *File = Clang->getFileManager().getFile(Filename);
- if (!File || File == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))
+ auto FileOrErr = Clang->getFileManager().getFile(Filename);
+ if (!FileOrErr ||
+ *FileOrErr == SourceMgr.getFileEntryForID(SourceMgr.getMainFileID()))
continue;
+ auto File = *FileOrErr;
if (time_t ModTime = File->getModificationTime()) {
FilesInPreamble[File->getName()] =
PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(),
@@ -533,21 +535,15 @@ PrecompiledPreamble::TempPCHFile::CreateNewPreamblePCHFile() {
// FIXME: This is a hack so that we can override the preamble file during
// crash-recovery testing, which is the only case where the preamble files
// are not necessarily cleaned up.
- const char *TmpFile = ::getenv("CINDEXTEST_PREAMBLE_FILE");
- if (TmpFile)
- return TempPCHFile::createFromCustomPath(TmpFile);
- return TempPCHFile::createInSystemTempDir("preamble", "pch");
-}
+ if (const char *TmpFile = ::getenv("CINDEXTEST_PREAMBLE_FILE"))
+ return TempPCHFile(TmpFile);
-llvm::ErrorOr<PrecompiledPreamble::TempPCHFile>
-PrecompiledPreamble::TempPCHFile::createInSystemTempDir(const Twine &Prefix,
- StringRef Suffix) {
llvm::SmallString<64> File;
// Using a version of createTemporaryFile with a file descriptor guarantees
// that we would never get a race condition in a multi-threaded setting
// (i.e., multiple threads getting the same temporary path).
int FD;
- auto EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, FD, File);
+ auto EC = llvm::sys::fs::createTemporaryFile("preamble", "pch", FD, File);
if (EC)
return EC;
// We only needed to make sure the file exists, close the file right away.
@@ -555,11 +551,6 @@ PrecompiledPreamble::TempPCHFile::createInSystemTempDir(const Twine &Prefix,
return TempPCHFile(std::move(File).str());
}
-llvm::ErrorOr<PrecompiledPreamble::TempPCHFile>
-PrecompiledPreamble::TempPCHFile::createFromCustomPath(const Twine &Path) {
- return TempPCHFile(Path.str());
-}
-
PrecompiledPreamble::TempPCHFile::TempPCHFile(std::string FilePath)
: FilePath(std::move(FilePath)) {
TemporaryFiles::getInstance().addFile(*this->FilePath);