aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp73
1 files changed, 35 insertions, 38 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp b/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
index 783d1f9d0919..f5e291b7fe17 100644
--- a/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
@@ -30,6 +30,7 @@
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/LangStandard.h"
#include "clang/Basic/Module.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
@@ -83,8 +84,8 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Mutex.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
@@ -95,6 +96,7 @@
#include <cstdio>
#include <cstdlib>
#include <memory>
+#include <mutex>
#include <string>
#include <tuple>
#include <utility>
@@ -818,7 +820,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
/*isysroot=*/"",
/*DisableValidation=*/disableValid, AllowPCHWithCompilerErrors);
- AST->Reader->setListener(llvm::make_unique<ASTInfoCollector>(
+ AST->Reader->setListener(std::make_unique<ASTInfoCollector>(
*AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts,
AST->TargetOpts, AST->Target, Counter));
@@ -998,9 +1000,9 @@ public:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
CI.getPreprocessor().addPPCallbacks(
- llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
+ std::make_unique<MacroDefinitionTrackerPPCallbacks>(
Unit.getCurrentTopLevelHashValue()));
- return llvm::make_unique<TopLevelDeclTrackerConsumer>(
+ return std::make_unique<TopLevelDeclTrackerConsumer>(
Unit, Unit.getCurrentTopLevelHashValue());
}
@@ -1048,7 +1050,7 @@ public:
}
std::unique_ptr<PPCallbacks> createPPCallbacks() override {
- return llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
+ return std::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
}
private:
@@ -1153,7 +1155,7 @@ bool ASTUnit::Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
InputKind::Source &&
"FIXME: AST inputs not yet supported here!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
- InputKind::LLVM_IR &&
+ Language::LLVM_IR &&
"IR inputs not support here!");
// Configure the various subsystems.
@@ -1586,7 +1588,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
InputKind::Source &&
"FIXME: AST inputs not yet supported here!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
- InputKind::LLVM_IR &&
+ Language::LLVM_IR &&
"IR inputs not support here!");
// Configure the various subsystems.
@@ -1623,15 +1625,15 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
if (Persistent && !TrackerAct) {
Clang->getPreprocessor().addPPCallbacks(
- llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
+ std::make_unique<MacroDefinitionTrackerPPCallbacks>(
AST->getCurrentTopLevelHashValue()));
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
if (Clang->hasASTConsumer())
Consumers.push_back(Clang->takeASTConsumer());
- Consumers.push_back(llvm::make_unique<TopLevelDeclTrackerConsumer>(
+ Consumers.push_back(std::make_unique<TopLevelDeclTrackerConsumer>(
*AST, AST->getCurrentTopLevelHashValue()));
Clang->setASTConsumer(
- llvm::make_unique<MultiplexConsumer>(std::move(Consumers)));
+ std::make_unique<MultiplexConsumer>(std::move(Consumers)));
}
if (llvm::Error Err = Act->Execute()) {
consumeError(std::move(Err)); // FIXME this drops errors on the floor.
@@ -1734,6 +1736,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion,
bool AllowPCHWithCompilerErrors, SkipFunctionBodiesScope SkipFunctionBodies,
bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization,
+ bool RetainExcludedConditionalBlocks,
llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
assert(Diags.get() && "no DiagnosticsEngine was provided");
@@ -1761,6 +1764,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;
PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
PPOpts.SingleFileParseMode = SingleFileParse;
+ PPOpts.RetainExcludedConditionalBlocks = RetainExcludedConditionalBlocks;
// Override the resources path.
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
@@ -2210,7 +2214,7 @@ void ASTUnit::CodeComplete(
InputKind::Source &&
"FIXME: AST inputs not yet supported here!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
- InputKind::LLVM_IR &&
+ Language::LLVM_IR &&
"IR inputs not support here!");
// Use the source and file managers that we were given.
@@ -2298,26 +2302,19 @@ bool ASTUnit::Save(StringRef File) {
SmallString<128> TempPath;
TempPath = File;
TempPath += "-%%%%%%%%";
- int fd;
- if (llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath))
- return true;
-
// FIXME: Can we somehow regenerate the stat cache here, or do we need to
// unconditionally create a stat cache when we parse the file?
- llvm::raw_fd_ostream Out(fd, /*shouldClose=*/true);
-
- serialize(Out);
- Out.close();
- if (Out.has_error()) {
- Out.clear_error();
- return true;
- }
- if (llvm::sys::fs::rename(TempPath, File)) {
- llvm::sys::fs::remove(TempPath);
+ if (llvm::Error Err = llvm::writeFileAtomically(
+ TempPath, File, [this](llvm::raw_ostream &Out) {
+ return serialize(Out) ? llvm::make_error<llvm::StringError>(
+ "ASTUnit serialization failed",
+ llvm::inconvertibleErrorCode())
+ : llvm::Error::success();
+ })) {
+ consumeError(std::move(Err));
return true;
}
-
return false;
}
@@ -2368,13 +2365,13 @@ void ASTUnit::TranslateStoredDiagnostics(
// Rebuild the StoredDiagnostic.
if (SD.Filename.empty())
continue;
- const FileEntry *FE = FileMgr.getFile(SD.Filename);
+ auto FE = FileMgr.getFile(SD.Filename);
if (!FE)
continue;
SourceLocation FileLoc;
auto ItFileID = PreambleSrcLocCache.find(SD.Filename);
if (ItFileID == PreambleSrcLocCache.end()) {
- FileID FID = SrcMgr.translateFile(FE);
+ FileID FID = SrcMgr.translateFile(*FE);
FileLoc = SrcMgr.getLocForStartOfFile(FID);
PreambleSrcLocCache[SD.Filename] = FileLoc;
} else {
@@ -2667,17 +2664,17 @@ bool ASTUnit::isModuleFile() const {
InputKind ASTUnit::getInputKind() const {
auto &LangOpts = getLangOpts();
- InputKind::Language Lang;
+ Language Lang;
if (LangOpts.OpenCL)
- Lang = InputKind::OpenCL;
+ Lang = Language::OpenCL;
else if (LangOpts.CUDA)
- Lang = InputKind::CUDA;
+ Lang = Language::CUDA;
else if (LangOpts.RenderScript)
- Lang = InputKind::RenderScript;
+ Lang = Language::RenderScript;
else if (LangOpts.CPlusPlus)
- Lang = LangOpts.ObjC ? InputKind::ObjCXX : InputKind::CXX;
+ Lang = LangOpts.ObjC ? Language::ObjCXX : Language::CXX;
else
- Lang = LangOpts.ObjC ? InputKind::ObjC : InputKind::C;
+ Lang = LangOpts.ObjC ? Language::ObjC : Language::C;
InputKind::Format Fmt = InputKind::Source;
if (LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap)
@@ -2691,20 +2688,20 @@ InputKind ASTUnit::getInputKind() const {
#ifndef NDEBUG
ASTUnit::ConcurrencyState::ConcurrencyState() {
- Mutex = new llvm::sys::MutexImpl(/*recursive=*/true);
+ Mutex = new std::recursive_mutex;
}
ASTUnit::ConcurrencyState::~ConcurrencyState() {
- delete static_cast<llvm::sys::MutexImpl *>(Mutex);
+ delete static_cast<std::recursive_mutex *>(Mutex);
}
void ASTUnit::ConcurrencyState::start() {
- bool acquired = static_cast<llvm::sys::MutexImpl *>(Mutex)->tryacquire();
+ bool acquired = static_cast<std::recursive_mutex *>(Mutex)->try_lock();
assert(acquired && "Concurrent access to ASTUnit!");
}
void ASTUnit::ConcurrencyState::finish() {
- static_cast<llvm::sys::MutexImpl *>(Mutex)->release();
+ static_cast<std::recursive_mutex *>(Mutex)->unlock();
}
#else // NDEBUG