aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-04-14 21:41:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-06-22 18:20:56 +0000
commitbdd1243df58e60e85101c09001d9812a789b6bc4 (patch)
treea1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
parent781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff)
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp49
1 files changed, 38 insertions, 11 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp b/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
index 5a157d665a9d..3b4f25182ac9 100644
--- a/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/ASTUnit.cpp
@@ -66,8 +66,6 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
-#include "llvm/ADT/None.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
@@ -87,6 +85,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SaveAndRestore.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
@@ -98,6 +97,7 @@
#include <cstdlib>
#include <memory>
#include <mutex>
+#include <optional>
#include <string>
#include <tuple>
#include <utility>
@@ -524,6 +524,7 @@ class ASTInfoCollector : public ASTReaderListener {
IntrusiveRefCntPtr<TargetInfo> &Target;
unsigned &Counter;
bool InitializedLanguage = false;
+ bool InitializedHeaderSearchPaths = false;
public:
ASTInfoCollector(Preprocessor &PP, ASTContext *Context,
@@ -550,7 +551,34 @@ public:
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
StringRef SpecificModuleCachePath,
bool Complain) override {
+ // Preserve previously set header search paths.
+ llvm::SaveAndRestore X(this->HSOpts.UserEntries);
+ llvm::SaveAndRestore Y(this->HSOpts.SystemHeaderPrefixes);
+ llvm::SaveAndRestore Z(this->HSOpts.VFSOverlayFiles);
+
this->HSOpts = HSOpts;
+
+ return false;
+ }
+
+ bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts,
+ bool Complain) override {
+ if (InitializedHeaderSearchPaths)
+ return false;
+
+ this->HSOpts.UserEntries = HSOpts.UserEntries;
+ this->HSOpts.SystemHeaderPrefixes = HSOpts.SystemHeaderPrefixes;
+ this->HSOpts.VFSOverlayFiles = HSOpts.VFSOverlayFiles;
+
+ // Initialize the FileManager. We can't do this in update(), since that
+ // performs the initialization too late (once both target and language
+ // options are read).
+ PP.getFileManager().setVirtualFileSystem(createVFSFromOverlayFiles(
+ HSOpts.VFSOverlayFiles, PP.getDiagnostics(),
+ PP.getFileManager().getVirtualFileSystemPtr()));
+
+ InitializedHeaderSearchPaths = true;
+
return false;
}
@@ -705,10 +733,10 @@ void FilterAndStoreDiagnosticConsumer::HandleDiagnostic(
}
if (StandaloneDiags) {
- llvm::Optional<StoredDiagnostic> StoredDiag = None;
+ std::optional<StoredDiagnostic> StoredDiag;
if (!ResultDiag) {
StoredDiag.emplace(Level, Info);
- ResultDiag = StoredDiag.getPointer();
+ ResultDiag = &*StoredDiag;
}
StandaloneDiags->push_back(
makeStandaloneDiagnostic(*LangOpts, *ResultDiag));
@@ -1349,7 +1377,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble(
SmallVector<StoredDiagnostic, 4> NewPreambleDiags;
ASTUnitPreambleCallbacks Callbacks;
{
- llvm::Optional<CaptureDroppedDiagnostics> Capture;
+ std::optional<CaptureDroppedDiagnostics> Capture;
if (CaptureDiagnostics != CaptureDiagsKind::None)
Capture.emplace(CaptureDiagnostics, *Diagnostics, &NewPreambleDiags,
&NewPreambleDiagsStandalone);
@@ -1715,8 +1743,8 @@ 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,
+ bool RetainExcludedConditionalBlocks, std::optional<StringRef> ModuleFormat,
+ std::unique_ptr<ASTUnit> *ErrAST,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
assert(Diags.get() && "no DiagnosticsEngine was provided");
@@ -1732,8 +1760,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(
CIOpts.VFS = VFS;
CIOpts.Diags = Diags;
CIOpts.ProbePrecompiled = true; // FIXME: historical default. Needed?
- CI = createInvocation(llvm::makeArrayRef(ArgBegin, ArgEnd),
- std::move(CIOpts));
+ CI = createInvocation(llvm::ArrayRef(ArgBegin, ArgEnd), std::move(CIOpts));
if (!CI)
return nullptr;
}
@@ -2214,10 +2241,10 @@ void ASTUnit::CodeComplete(
Clang->setCodeCompletionConsumer(AugmentedConsumer);
auto getUniqueID =
- [&FileMgr](StringRef Filename) -> Optional<llvm::sys::fs::UniqueID> {
+ [&FileMgr](StringRef Filename) -> std::optional<llvm::sys::fs::UniqueID> {
if (auto Status = FileMgr.getVirtualFileSystem().status(Filename))
return Status->getUniqueID();
- return None;
+ return std::nullopt;
};
auto hasSameUniqueID = [getUniqueID](StringRef LHS, StringRef RHS) {