summaryrefslogtreecommitdiff
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.cpp77
1 files changed, 40 insertions, 37 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp b/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
index b3264952ff47..783d1f9d0919 100644
--- a/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
@@ -30,7 +30,6 @@
#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"
@@ -61,7 +60,7 @@
#include "clang/Serialization/ASTWriter.h"
#include "clang/Serialization/ContinuousRangeMap.h"
#include "clang/Serialization/InMemoryModuleCache.h"
-#include "clang/Serialization/ModuleFile.h"
+#include "clang/Serialization/Module.h"
#include "clang/Serialization/PCHContainerOperations.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
@@ -84,8 +83,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"
@@ -96,7 +95,6 @@
#include <cstdio>
#include <cstdlib>
#include <memory>
-#include <mutex>
#include <string>
#include <tuple>
#include <utility>
@@ -820,7 +818,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
/*isysroot=*/"",
/*DisableValidation=*/disableValid, AllowPCHWithCompilerErrors);
- AST->Reader->setListener(std::make_unique<ASTInfoCollector>(
+ AST->Reader->setListener(llvm::make_unique<ASTInfoCollector>(
*AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts,
AST->TargetOpts, AST->Target, Counter));
@@ -1000,9 +998,9 @@ public:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
CI.getPreprocessor().addPPCallbacks(
- std::make_unique<MacroDefinitionTrackerPPCallbacks>(
+ llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
Unit.getCurrentTopLevelHashValue()));
- return std::make_unique<TopLevelDeclTrackerConsumer>(
+ return llvm::make_unique<TopLevelDeclTrackerConsumer>(
Unit, Unit.getCurrentTopLevelHashValue());
}
@@ -1050,7 +1048,7 @@ public:
}
std::unique_ptr<PPCallbacks> createPPCallbacks() override {
- return std::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
+ return llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
}
private:
@@ -1155,7 +1153,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() !=
- Language::LLVM_IR &&
+ InputKind::LLVM_IR &&
"IR inputs not support here!");
// Configure the various subsystems.
@@ -1457,7 +1455,7 @@ void ASTUnit::transferASTDataFromCompilerInstance(CompilerInstance &CI) {
CI.setFileManager(nullptr);
if (CI.hasTarget())
Target = &CI.getTarget();
- Reader = CI.getASTReader();
+ Reader = CI.getModuleManager();
HadModuleLoaderFatalFailure = CI.hadModuleLoaderFatalFailure();
}
@@ -1588,7 +1586,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
InputKind::Source &&
"FIXME: AST inputs not yet supported here!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
- Language::LLVM_IR &&
+ InputKind::LLVM_IR &&
"IR inputs not support here!");
// Configure the various subsystems.
@@ -1625,15 +1623,15 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(
if (Persistent && !TrackerAct) {
Clang->getPreprocessor().addPPCallbacks(
- std::make_unique<MacroDefinitionTrackerPPCallbacks>(
+ llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(
AST->getCurrentTopLevelHashValue()));
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
if (Clang->hasASTConsumer())
Consumers.push_back(Clang->takeASTConsumer());
- Consumers.push_back(std::make_unique<TopLevelDeclTrackerConsumer>(
+ Consumers.push_back(llvm::make_unique<TopLevelDeclTrackerConsumer>(
*AST, AST->getCurrentTopLevelHashValue()));
Clang->setASTConsumer(
- std::make_unique<MultiplexConsumer>(std::move(Consumers)));
+ llvm::make_unique<MultiplexConsumer>(std::move(Consumers)));
}
if (llvm::Error Err = Act->Execute()) {
consumeError(std::move(Err)); // FIXME this drops errors on the floor.
@@ -1736,7 +1734,6 @@ 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");
@@ -1764,7 +1761,6 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;
PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
PPOpts.SingleFileParseMode = SingleFileParse;
- PPOpts.RetainExcludedConditionalBlocks = RetainExcludedConditionalBlocks;
// Override the resources path.
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
@@ -2214,7 +2210,7 @@ void ASTUnit::CodeComplete(
InputKind::Source &&
"FIXME: AST inputs not yet supported here!");
assert(Clang->getFrontendOpts().Inputs[0].getKind().getLanguage() !=
- Language::LLVM_IR &&
+ InputKind::LLVM_IR &&
"IR inputs not support here!");
// Use the source and file managers that we were given.
@@ -2302,19 +2298,26 @@ 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::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));
+ if (llvm::sys::fs::rename(TempPath, File)) {
+ llvm::sys::fs::remove(TempPath);
return true;
}
+
return false;
}
@@ -2365,13 +2368,13 @@ void ASTUnit::TranslateStoredDiagnostics(
// Rebuild the StoredDiagnostic.
if (SD.Filename.empty())
continue;
- auto FE = FileMgr.getFile(SD.Filename);
+ const FileEntry *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 {
@@ -2664,17 +2667,17 @@ bool ASTUnit::isModuleFile() const {
InputKind ASTUnit::getInputKind() const {
auto &LangOpts = getLangOpts();
- Language Lang;
+ InputKind::Language Lang;
if (LangOpts.OpenCL)
- Lang = Language::OpenCL;
+ Lang = InputKind::OpenCL;
else if (LangOpts.CUDA)
- Lang = Language::CUDA;
+ Lang = InputKind::CUDA;
else if (LangOpts.RenderScript)
- Lang = Language::RenderScript;
+ Lang = InputKind::RenderScript;
else if (LangOpts.CPlusPlus)
- Lang = LangOpts.ObjC ? Language::ObjCXX : Language::CXX;
+ Lang = LangOpts.ObjC ? InputKind::ObjCXX : InputKind::CXX;
else
- Lang = LangOpts.ObjC ? Language::ObjC : Language::C;
+ Lang = LangOpts.ObjC ? InputKind::ObjC : InputKind::C;
InputKind::Format Fmt = InputKind::Source;
if (LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap)
@@ -2688,20 +2691,20 @@ InputKind ASTUnit::getInputKind() const {
#ifndef NDEBUG
ASTUnit::ConcurrencyState::ConcurrencyState() {
- Mutex = new std::recursive_mutex;
+ Mutex = new llvm::sys::MutexImpl(/*recursive=*/true);
}
ASTUnit::ConcurrencyState::~ConcurrencyState() {
- delete static_cast<std::recursive_mutex *>(Mutex);
+ delete static_cast<llvm::sys::MutexImpl *>(Mutex);
}
void ASTUnit::ConcurrencyState::start() {
- bool acquired = static_cast<std::recursive_mutex *>(Mutex)->try_lock();
+ bool acquired = static_cast<llvm::sys::MutexImpl *>(Mutex)->tryacquire();
assert(acquired && "Concurrent access to ASTUnit!");
}
void ASTUnit::ConcurrencyState::finish() {
- static_cast<std::recursive_mutex *>(Mutex)->unlock();
+ static_cast<llvm::sys::MutexImpl *>(Mutex)->release();
}
#else // NDEBUG