-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang] Do not share ownership of PreprocessorOptions
#133467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() { | ||
| return PPOpts; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the primary goal of this PR.
|
@llvm/pr-subscribers-clangd Author: Jan Svoboda (jansvoboda11) ChangesThis PR makes it so that Patch is 29.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133467.diff 17 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index a15850cb63542..03a3e8404e069 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -89,15 +89,14 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
HeaderInfo = std::make_unique<HeaderSearch>(HSOpts, Sources, Diags, LangOpts,
&Compiler.getTarget());
- auto PO = std::make_shared<PreprocessorOptions>();
- *PO = Compiler.getPreprocessorOpts();
-
- PP = std::make_unique<clang::Preprocessor>(PO, Diags, LangOpts, Sources,
- *HeaderInfo, ModuleLoader,
- /*IILookup=*/nullptr,
- /*OwnsHeaderSearch=*/false);
+ PP = std::make_unique<clang::Preprocessor>(Compiler.getPreprocessorOpts(),
+ Diags, LangOpts, Sources,
+ *HeaderInfo, ModuleLoader,
+ /*IILookup=*/nullptr,
+ /*OwnsHeaderSearch=*/false);
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
- InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
+ InitializePreprocessor(*PP, Compiler.getPreprocessorOpts(),
+ Compiler.getPCHContainerReader(),
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
Compiler.getTarget().getTriple());
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 03c5f5e1b5993..c1878f91b5e16 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -202,9 +202,10 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
/*Target=*/nullptr);
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModuleLoader;
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
- SourceMgr, HeaderInfo, ModuleLoader);
+ Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
+ ModuleLoader);
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
PCHContainerOperations PCHOperations;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 1e4d2da86c2be..f71d27813b2a1 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -272,9 +272,6 @@ class CompilerInvocation : public CompilerInvocationBase {
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
return HSOpts;
}
- std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
- return PPOpts;
- }
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
/// @}
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 4fdc4e0439125..24bb524783e93 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -140,7 +140,7 @@ class Preprocessor {
friend class VariadicMacroScopeGuard;
llvm::unique_function<void(const clang::Token &)> OnToken;
- std::shared_ptr<const PreprocessorOptions> PPOpts;
+ const PreprocessorOptions &PPOpts;
DiagnosticsEngine *Diags;
const LangOptions &LangOpts;
const TargetInfo *Target = nullptr;
@@ -1165,10 +1165,9 @@ class Preprocessor {
void updateOutOfDateIdentifier(const IdentifierInfo &II) const;
public:
- Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
- DiagnosticsEngine &diags, const LangOptions &LangOpts,
- SourceManager &SM, HeaderSearch &Headers,
- ModuleLoader &TheModuleLoader,
+ Preprocessor(const PreprocessorOptions &PPOpts, DiagnosticsEngine &diags,
+ const LangOptions &LangOpts, SourceManager &SM,
+ HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup = nullptr,
bool OwnsHeaderSearch = false,
TranslationUnitKind TUKind = TU_Complete);
@@ -1195,9 +1194,8 @@ class Preprocessor {
/// Cleanup after model file parsing
void FinalizeForModelFile();
- /// Retrieve the preprocessor options used to initialize this
- /// preprocessor.
- const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
+ /// Retrieve the preprocessor options used to initialize this preprocessor.
+ const PreprocessorOptions &getPreprocessorOpts() const { return PPOpts; }
DiagnosticsEngine &getDiagnostics() const { return *Diags; }
void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0a5f1cfd1a264..04ddc93415507 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -844,7 +844,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
HeaderSearch &HeaderInfo = *AST->HeaderInfo;
AST->PP = std::make_shared<Preprocessor>(
- AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
+ *AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
AST->getSourceManager(), HeaderInfo, AST->ModuleLoader,
/*IILookup=*/nullptr,
/*OwnsHeaderSearch=*/false);
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 91093d3ccb84c..9cab17ae70eeb 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -452,7 +452,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
HeaderSearch *HeaderInfo =
new HeaderSearch(getHeaderSearchOpts(), getSourceManager(),
getDiagnostics(), getLangOpts(), &getTarget());
- PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOptsPtr(),
+ PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOpts(),
getDiagnostics(), getLangOpts(),
getSourceManager(), *HeaderInfo, *this,
/*IdentifierInfoLookup=*/nullptr,
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a29b73f97ab7e..0b53524e23641 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1154,7 +1154,7 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool isAngled, bool OpenFile,
}
}
- for (const auto &Entry : PPOpts->EmbedEntries) {
+ for (const auto &Entry : PPOpts.EmbedEntries) {
LookupPath.clear();
SeparateComponents(LookupPath, Entry, Filename, false);
llvm::Expected<FileEntryRef> ShouldBeEntry = FM.getFileRef(
@@ -2341,7 +2341,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
enum { Enter, Import, Skip, IncludeLimitReached } Action = Enter;
- if (PPOpts->SingleFileParseMode)
+ if (PPOpts.SingleFileParseMode)
Action = IncludeLimitReached;
// If we've reached the max allowed include depth, it is usually due to an
@@ -3420,11 +3420,11 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(DirectiveTok.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && !MI) {
+ if (PPOpts.SingleFileParseMode && !MI) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
@@ -3475,11 +3475,11 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
IfToken.getLocation(), DER.ExprRange,
(ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(IfToken.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
+ if (PPOpts.SingleFileParseMode && DER.IncludedUndefinedIds) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
@@ -3546,10 +3546,10 @@ void Preprocessor::HandleElseDirective(Token &Result, const Token &HashToken) {
if (Callbacks)
Callbacks->Else(Result.getLocation(), CI.IfLoc);
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(Result.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false,
@@ -3626,10 +3626,10 @@ void Preprocessor::HandleElifFamilyDirective(Token &ElifToken,
}
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(ElifToken.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index e1dcc5499170e..a373a52506a24 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -561,7 +561,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
// Reached the end of the compilation without finding the through header.
Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 0;
+ << PPOpts.PCHThroughHeader << 0;
}
if (!isIncrementalProcessingEnabled())
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index ff99575dc611b..c25a3efd899e0 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -77,13 +77,13 @@ LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
ExternalPreprocessorSource::~ExternalPreprocessorSource() = default;
-Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
+Preprocessor::Preprocessor(const PreprocessorOptions &PPOpts,
DiagnosticsEngine &diags, const LangOptions &opts,
SourceManager &SM, HeaderSearch &Headers,
ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup, bool OwnsHeaders,
TranslationUnitKind TUKind)
- : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts),
+ : PPOpts(PPOpts), Diags(&diags), LangOpts(opts),
FileMgr(Headers.getFileMgr()), SourceMgr(SM),
ScratchBuf(new ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
@@ -156,11 +156,11 @@ Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
SkippingUntilPragmaHdrStop = true;
// If using a PCH with a through header, start skipping tokens.
- if (!this->PPOpts->PCHThroughHeader.empty() &&
- !this->PPOpts->ImplicitPCHInclude.empty())
+ if (!this->PPOpts.PCHThroughHeader.empty() &&
+ !this->PPOpts.ImplicitPCHInclude.empty())
SkippingUntilPCHThroughHeader = true;
- if (this->PPOpts->GeneratePreamble)
+ if (this->PPOpts.GeneratePreamble)
PreambleConditionalStack.startRecording();
MaxTokens = LangOpts.MaxTokens;
@@ -577,18 +577,18 @@ void Preprocessor::EnterMainSourceFile() {
// Start parsing the predefines.
EnterSourceFile(FID, nullptr, SourceLocation());
- if (!PPOpts->PCHThroughHeader.empty()) {
+ if (!PPOpts.PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
OptionalFileEntryRef File = LookupFile(
- SourceLocation(), PPOpts->PCHThroughHeader,
+ SourceLocation(), PPOpts.PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr,
/*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr,
/*IsFrameworkFound=*/nullptr);
if (!File) {
Diag(SourceLocation(), diag::err_pp_through_header_not_found)
- << PPOpts->PCHThroughHeader;
+ << PPOpts.PCHThroughHeader;
return;
}
setPCHThroughHeaderFileID(
@@ -614,21 +614,21 @@ bool Preprocessor::isPCHThroughHeader(const FileEntry *FE) {
}
bool Preprocessor::creatingPCHWithThroughHeader() {
- return TUKind == TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind == TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::usingPCHWithThroughHeader() {
- return TUKind != TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind != TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::creatingPCHWithPragmaHdrStop() {
- return TUKind == TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind == TU_Prefix && PPOpts.PCHWithHdrStop;
}
bool Preprocessor::usingPCHWithPragmaHdrStop() {
- return TUKind != TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind != TU_Prefix && PPOpts.PCHWithHdrStop;
}
/// Skip tokens until after the #include of the through header or
@@ -657,8 +657,8 @@ void Preprocessor::SkipTokensWhileUsingPCH() {
if (ReachedMainFileEOF) {
if (UsingPCHThroughHeader)
Diag(SourceLocation(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 1;
- else if (!PPOpts->PCHWithHdrStopCreate)
+ << PPOpts.PCHThroughHeader << 1;
+ else if (!PPOpts.PCHWithHdrStopCreate)
Diag(SourceLocation(), diag::err_pp_pragma_hdrstop_not_seen);
}
}
diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 48db9d46180ab..19074d7dcfdd4 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -60,11 +60,10 @@ class MacroExpansionContextTest : public ::testing::Test {
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
HeaderSearchOptions HSOpts;
TrivialModuleLoader ModLoader;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, Target.get());
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
auto Ctx = std::make_unique<MacroExpansionContext>(LangOpts);
diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp
index 1f2dba6fcc5d8..201c3f9a68d1d 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -136,12 +136,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
SourceMgr.setMainFileID(mainFileID);
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup =*/nullptr, /*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
@@ -186,12 +185,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithTokenSplit) {
SourceMgr.createFileID(llvm::MemoryBuffer::getMemBuffer(main)));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
llvm::SmallString<8> Scratch;
@@ -462,11 +460,10 @@ TEST_F(SourceManagerTest, ResetsIncludeLocMap) {
auto ParseFile = [&] {
TrivialModuleLoader ModLoader;
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
PP.LexTokensUntilEOF();
@@ -538,13 +535,12 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
// Ensure we can get expanded locations in presence of implicit includes.
// These are different than normal includes since predefines buffer doesn't
// have a valid insertion location.
@@ -657,12 +653,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
std::vector<MacroAction> Macros;
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang...
[truncated]
|
|
@llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesThis PR makes it so that Patch is 29.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133467.diff 17 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index a15850cb63542..03a3e8404e069 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -89,15 +89,14 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
HeaderInfo = std::make_unique<HeaderSearch>(HSOpts, Sources, Diags, LangOpts,
&Compiler.getTarget());
- auto PO = std::make_shared<PreprocessorOptions>();
- *PO = Compiler.getPreprocessorOpts();
-
- PP = std::make_unique<clang::Preprocessor>(PO, Diags, LangOpts, Sources,
- *HeaderInfo, ModuleLoader,
- /*IILookup=*/nullptr,
- /*OwnsHeaderSearch=*/false);
+ PP = std::make_unique<clang::Preprocessor>(Compiler.getPreprocessorOpts(),
+ Diags, LangOpts, Sources,
+ *HeaderInfo, ModuleLoader,
+ /*IILookup=*/nullptr,
+ /*OwnsHeaderSearch=*/false);
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
- InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
+ InitializePreprocessor(*PP, Compiler.getPreprocessorOpts(),
+ Compiler.getPCHContainerReader(),
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
Compiler.getTarget().getTriple());
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 03c5f5e1b5993..c1878f91b5e16 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -202,9 +202,10 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
/*Target=*/nullptr);
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModuleLoader;
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
- SourceMgr, HeaderInfo, ModuleLoader);
+ Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
+ ModuleLoader);
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
PCHContainerOperations PCHOperations;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 1e4d2da86c2be..f71d27813b2a1 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -272,9 +272,6 @@ class CompilerInvocation : public CompilerInvocationBase {
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
return HSOpts;
}
- std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
- return PPOpts;
- }
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
/// @}
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 4fdc4e0439125..24bb524783e93 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -140,7 +140,7 @@ class Preprocessor {
friend class VariadicMacroScopeGuard;
llvm::unique_function<void(const clang::Token &)> OnToken;
- std::shared_ptr<const PreprocessorOptions> PPOpts;
+ const PreprocessorOptions &PPOpts;
DiagnosticsEngine *Diags;
const LangOptions &LangOpts;
const TargetInfo *Target = nullptr;
@@ -1165,10 +1165,9 @@ class Preprocessor {
void updateOutOfDateIdentifier(const IdentifierInfo &II) const;
public:
- Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
- DiagnosticsEngine &diags, const LangOptions &LangOpts,
- SourceManager &SM, HeaderSearch &Headers,
- ModuleLoader &TheModuleLoader,
+ Preprocessor(const PreprocessorOptions &PPOpts, DiagnosticsEngine &diags,
+ const LangOptions &LangOpts, SourceManager &SM,
+ HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup = nullptr,
bool OwnsHeaderSearch = false,
TranslationUnitKind TUKind = TU_Complete);
@@ -1195,9 +1194,8 @@ class Preprocessor {
/// Cleanup after model file parsing
void FinalizeForModelFile();
- /// Retrieve the preprocessor options used to initialize this
- /// preprocessor.
- const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
+ /// Retrieve the preprocessor options used to initialize this preprocessor.
+ const PreprocessorOptions &getPreprocessorOpts() const { return PPOpts; }
DiagnosticsEngine &getDiagnostics() const { return *Diags; }
void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0a5f1cfd1a264..04ddc93415507 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -844,7 +844,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
HeaderSearch &HeaderInfo = *AST->HeaderInfo;
AST->PP = std::make_shared<Preprocessor>(
- AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
+ *AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
AST->getSourceManager(), HeaderInfo, AST->ModuleLoader,
/*IILookup=*/nullptr,
/*OwnsHeaderSearch=*/false);
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 91093d3ccb84c..9cab17ae70eeb 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -452,7 +452,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
HeaderSearch *HeaderInfo =
new HeaderSearch(getHeaderSearchOpts(), getSourceManager(),
getDiagnostics(), getLangOpts(), &getTarget());
- PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOptsPtr(),
+ PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOpts(),
getDiagnostics(), getLangOpts(),
getSourceManager(), *HeaderInfo, *this,
/*IdentifierInfoLookup=*/nullptr,
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a29b73f97ab7e..0b53524e23641 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1154,7 +1154,7 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool isAngled, bool OpenFile,
}
}
- for (const auto &Entry : PPOpts->EmbedEntries) {
+ for (const auto &Entry : PPOpts.EmbedEntries) {
LookupPath.clear();
SeparateComponents(LookupPath, Entry, Filename, false);
llvm::Expected<FileEntryRef> ShouldBeEntry = FM.getFileRef(
@@ -2341,7 +2341,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
enum { Enter, Import, Skip, IncludeLimitReached } Action = Enter;
- if (PPOpts->SingleFileParseMode)
+ if (PPOpts.SingleFileParseMode)
Action = IncludeLimitReached;
// If we've reached the max allowed include depth, it is usually due to an
@@ -3420,11 +3420,11 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(DirectiveTok.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && !MI) {
+ if (PPOpts.SingleFileParseMode && !MI) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
@@ -3475,11 +3475,11 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
IfToken.getLocation(), DER.ExprRange,
(ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(IfToken.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
+ if (PPOpts.SingleFileParseMode && DER.IncludedUndefinedIds) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
@@ -3546,10 +3546,10 @@ void Preprocessor::HandleElseDirective(Token &Result, const Token &HashToken) {
if (Callbacks)
Callbacks->Else(Result.getLocation(), CI.IfLoc);
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(Result.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false,
@@ -3626,10 +3626,10 @@ void Preprocessor::HandleElifFamilyDirective(Token &ElifToken,
}
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(ElifToken.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index e1dcc5499170e..a373a52506a24 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -561,7 +561,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
// Reached the end of the compilation without finding the through header.
Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 0;
+ << PPOpts.PCHThroughHeader << 0;
}
if (!isIncrementalProcessingEnabled())
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index ff99575dc611b..c25a3efd899e0 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -77,13 +77,13 @@ LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
ExternalPreprocessorSource::~ExternalPreprocessorSource() = default;
-Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
+Preprocessor::Preprocessor(const PreprocessorOptions &PPOpts,
DiagnosticsEngine &diags, const LangOptions &opts,
SourceManager &SM, HeaderSearch &Headers,
ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup, bool OwnsHeaders,
TranslationUnitKind TUKind)
- : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts),
+ : PPOpts(PPOpts), Diags(&diags), LangOpts(opts),
FileMgr(Headers.getFileMgr()), SourceMgr(SM),
ScratchBuf(new ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
@@ -156,11 +156,11 @@ Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
SkippingUntilPragmaHdrStop = true;
// If using a PCH with a through header, start skipping tokens.
- if (!this->PPOpts->PCHThroughHeader.empty() &&
- !this->PPOpts->ImplicitPCHInclude.empty())
+ if (!this->PPOpts.PCHThroughHeader.empty() &&
+ !this->PPOpts.ImplicitPCHInclude.empty())
SkippingUntilPCHThroughHeader = true;
- if (this->PPOpts->GeneratePreamble)
+ if (this->PPOpts.GeneratePreamble)
PreambleConditionalStack.startRecording();
MaxTokens = LangOpts.MaxTokens;
@@ -577,18 +577,18 @@ void Preprocessor::EnterMainSourceFile() {
// Start parsing the predefines.
EnterSourceFile(FID, nullptr, SourceLocation());
- if (!PPOpts->PCHThroughHeader.empty()) {
+ if (!PPOpts.PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
OptionalFileEntryRef File = LookupFile(
- SourceLocation(), PPOpts->PCHThroughHeader,
+ SourceLocation(), PPOpts.PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr,
/*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr,
/*IsFrameworkFound=*/nullptr);
if (!File) {
Diag(SourceLocation(), diag::err_pp_through_header_not_found)
- << PPOpts->PCHThroughHeader;
+ << PPOpts.PCHThroughHeader;
return;
}
setPCHThroughHeaderFileID(
@@ -614,21 +614,21 @@ bool Preprocessor::isPCHThroughHeader(const FileEntry *FE) {
}
bool Preprocessor::creatingPCHWithThroughHeader() {
- return TUKind == TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind == TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::usingPCHWithThroughHeader() {
- return TUKind != TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind != TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::creatingPCHWithPragmaHdrStop() {
- return TUKind == TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind == TU_Prefix && PPOpts.PCHWithHdrStop;
}
bool Preprocessor::usingPCHWithPragmaHdrStop() {
- return TUKind != TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind != TU_Prefix && PPOpts.PCHWithHdrStop;
}
/// Skip tokens until after the #include of the through header or
@@ -657,8 +657,8 @@ void Preprocessor::SkipTokensWhileUsingPCH() {
if (ReachedMainFileEOF) {
if (UsingPCHThroughHeader)
Diag(SourceLocation(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 1;
- else if (!PPOpts->PCHWithHdrStopCreate)
+ << PPOpts.PCHThroughHeader << 1;
+ else if (!PPOpts.PCHWithHdrStopCreate)
Diag(SourceLocation(), diag::err_pp_pragma_hdrstop_not_seen);
}
}
diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 48db9d46180ab..19074d7dcfdd4 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -60,11 +60,10 @@ class MacroExpansionContextTest : public ::testing::Test {
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
HeaderSearchOptions HSOpts;
TrivialModuleLoader ModLoader;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, Target.get());
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
auto Ctx = std::make_unique<MacroExpansionContext>(LangOpts);
diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp
index 1f2dba6fcc5d8..201c3f9a68d1d 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -136,12 +136,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
SourceMgr.setMainFileID(mainFileID);
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup =*/nullptr, /*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
@@ -186,12 +185,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithTokenSplit) {
SourceMgr.createFileID(llvm::MemoryBuffer::getMemBuffer(main)));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
llvm::SmallString<8> Scratch;
@@ -462,11 +460,10 @@ TEST_F(SourceManagerTest, ResetsIncludeLocMap) {
auto ParseFile = [&] {
TrivialModuleLoader ModLoader;
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
PP.LexTokensUntilEOF();
@@ -538,13 +535,12 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
// Ensure we can get expanded locations in presence of implicit includes.
// These are different than normal includes since predefines buffer doesn't
// have a valid insertion location.
@@ -657,12 +653,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
std::vector<MacroAction> Macros;
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang...
[truncated]
|
|
@llvm/pr-subscribers-clang-tools-extra Author: Jan Svoboda (jansvoboda11) ChangesThis PR makes it so that Patch is 29.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133467.diff 17 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index a15850cb63542..03a3e8404e069 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -89,15 +89,14 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
HeaderInfo = std::make_unique<HeaderSearch>(HSOpts, Sources, Diags, LangOpts,
&Compiler.getTarget());
- auto PO = std::make_shared<PreprocessorOptions>();
- *PO = Compiler.getPreprocessorOpts();
-
- PP = std::make_unique<clang::Preprocessor>(PO, Diags, LangOpts, Sources,
- *HeaderInfo, ModuleLoader,
- /*IILookup=*/nullptr,
- /*OwnsHeaderSearch=*/false);
+ PP = std::make_unique<clang::Preprocessor>(Compiler.getPreprocessorOpts(),
+ Diags, LangOpts, Sources,
+ *HeaderInfo, ModuleLoader,
+ /*IILookup=*/nullptr,
+ /*OwnsHeaderSearch=*/false);
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
- InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
+ InitializePreprocessor(*PP, Compiler.getPreprocessorOpts(),
+ Compiler.getPCHContainerReader(),
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
Compiler.getTarget().getTriple());
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 03c5f5e1b5993..c1878f91b5e16 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -202,9 +202,10 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
/*Target=*/nullptr);
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModuleLoader;
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
- SourceMgr, HeaderInfo, ModuleLoader);
+ Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
+ ModuleLoader);
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
PCHContainerOperations PCHOperations;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 1e4d2da86c2be..f71d27813b2a1 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -272,9 +272,6 @@ class CompilerInvocation : public CompilerInvocationBase {
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
return HSOpts;
}
- std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
- return PPOpts;
- }
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
/// @}
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 4fdc4e0439125..24bb524783e93 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -140,7 +140,7 @@ class Preprocessor {
friend class VariadicMacroScopeGuard;
llvm::unique_function<void(const clang::Token &)> OnToken;
- std::shared_ptr<const PreprocessorOptions> PPOpts;
+ const PreprocessorOptions &PPOpts;
DiagnosticsEngine *Diags;
const LangOptions &LangOpts;
const TargetInfo *Target = nullptr;
@@ -1165,10 +1165,9 @@ class Preprocessor {
void updateOutOfDateIdentifier(const IdentifierInfo &II) const;
public:
- Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
- DiagnosticsEngine &diags, const LangOptions &LangOpts,
- SourceManager &SM, HeaderSearch &Headers,
- ModuleLoader &TheModuleLoader,
+ Preprocessor(const PreprocessorOptions &PPOpts, DiagnosticsEngine &diags,
+ const LangOptions &LangOpts, SourceManager &SM,
+ HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup = nullptr,
bool OwnsHeaderSearch = false,
TranslationUnitKind TUKind = TU_Complete);
@@ -1195,9 +1194,8 @@ class Preprocessor {
/// Cleanup after model file parsing
void FinalizeForModelFile();
- /// Retrieve the preprocessor options used to initialize this
- /// preprocessor.
- const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
+ /// Retrieve the preprocessor options used to initialize this preprocessor.
+ const PreprocessorOptions &getPreprocessorOpts() const { return PPOpts; }
DiagnosticsEngine &getDiagnostics() const { return *Diags; }
void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0a5f1cfd1a264..04ddc93415507 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -844,7 +844,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
HeaderSearch &HeaderInfo = *AST->HeaderInfo;
AST->PP = std::make_shared<Preprocessor>(
- AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
+ *AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
AST->getSourceManager(), HeaderInfo, AST->ModuleLoader,
/*IILookup=*/nullptr,
/*OwnsHeaderSearch=*/false);
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 91093d3ccb84c..9cab17ae70eeb 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -452,7 +452,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
HeaderSearch *HeaderInfo =
new HeaderSearch(getHeaderSearchOpts(), getSourceManager(),
getDiagnostics(), getLangOpts(), &getTarget());
- PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOptsPtr(),
+ PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOpts(),
getDiagnostics(), getLangOpts(),
getSourceManager(), *HeaderInfo, *this,
/*IdentifierInfoLookup=*/nullptr,
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a29b73f97ab7e..0b53524e23641 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1154,7 +1154,7 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool isAngled, bool OpenFile,
}
}
- for (const auto &Entry : PPOpts->EmbedEntries) {
+ for (const auto &Entry : PPOpts.EmbedEntries) {
LookupPath.clear();
SeparateComponents(LookupPath, Entry, Filename, false);
llvm::Expected<FileEntryRef> ShouldBeEntry = FM.getFileRef(
@@ -2341,7 +2341,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
enum { Enter, Import, Skip, IncludeLimitReached } Action = Enter;
- if (PPOpts->SingleFileParseMode)
+ if (PPOpts.SingleFileParseMode)
Action = IncludeLimitReached;
// If we've reached the max allowed include depth, it is usually due to an
@@ -3420,11 +3420,11 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(DirectiveTok.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && !MI) {
+ if (PPOpts.SingleFileParseMode && !MI) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
@@ -3475,11 +3475,11 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
IfToken.getLocation(), DER.ExprRange,
(ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(IfToken.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
+ if (PPOpts.SingleFileParseMode && DER.IncludedUndefinedIds) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
@@ -3546,10 +3546,10 @@ void Preprocessor::HandleElseDirective(Token &Result, const Token &HashToken) {
if (Callbacks)
Callbacks->Else(Result.getLocation(), CI.IfLoc);
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(Result.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false,
@@ -3626,10 +3626,10 @@ void Preprocessor::HandleElifFamilyDirective(Token &ElifToken,
}
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(ElifToken.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index e1dcc5499170e..a373a52506a24 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -561,7 +561,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
// Reached the end of the compilation without finding the through header.
Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 0;
+ << PPOpts.PCHThroughHeader << 0;
}
if (!isIncrementalProcessingEnabled())
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index ff99575dc611b..c25a3efd899e0 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -77,13 +77,13 @@ LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
ExternalPreprocessorSource::~ExternalPreprocessorSource() = default;
-Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
+Preprocessor::Preprocessor(const PreprocessorOptions &PPOpts,
DiagnosticsEngine &diags, const LangOptions &opts,
SourceManager &SM, HeaderSearch &Headers,
ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup, bool OwnsHeaders,
TranslationUnitKind TUKind)
- : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts),
+ : PPOpts(PPOpts), Diags(&diags), LangOpts(opts),
FileMgr(Headers.getFileMgr()), SourceMgr(SM),
ScratchBuf(new ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
@@ -156,11 +156,11 @@ Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
SkippingUntilPragmaHdrStop = true;
// If using a PCH with a through header, start skipping tokens.
- if (!this->PPOpts->PCHThroughHeader.empty() &&
- !this->PPOpts->ImplicitPCHInclude.empty())
+ if (!this->PPOpts.PCHThroughHeader.empty() &&
+ !this->PPOpts.ImplicitPCHInclude.empty())
SkippingUntilPCHThroughHeader = true;
- if (this->PPOpts->GeneratePreamble)
+ if (this->PPOpts.GeneratePreamble)
PreambleConditionalStack.startRecording();
MaxTokens = LangOpts.MaxTokens;
@@ -577,18 +577,18 @@ void Preprocessor::EnterMainSourceFile() {
// Start parsing the predefines.
EnterSourceFile(FID, nullptr, SourceLocation());
- if (!PPOpts->PCHThroughHeader.empty()) {
+ if (!PPOpts.PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
OptionalFileEntryRef File = LookupFile(
- SourceLocation(), PPOpts->PCHThroughHeader,
+ SourceLocation(), PPOpts.PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr,
/*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr,
/*IsFrameworkFound=*/nullptr);
if (!File) {
Diag(SourceLocation(), diag::err_pp_through_header_not_found)
- << PPOpts->PCHThroughHeader;
+ << PPOpts.PCHThroughHeader;
return;
}
setPCHThroughHeaderFileID(
@@ -614,21 +614,21 @@ bool Preprocessor::isPCHThroughHeader(const FileEntry *FE) {
}
bool Preprocessor::creatingPCHWithThroughHeader() {
- return TUKind == TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind == TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::usingPCHWithThroughHeader() {
- return TUKind != TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind != TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::creatingPCHWithPragmaHdrStop() {
- return TUKind == TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind == TU_Prefix && PPOpts.PCHWithHdrStop;
}
bool Preprocessor::usingPCHWithPragmaHdrStop() {
- return TUKind != TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind != TU_Prefix && PPOpts.PCHWithHdrStop;
}
/// Skip tokens until after the #include of the through header or
@@ -657,8 +657,8 @@ void Preprocessor::SkipTokensWhileUsingPCH() {
if (ReachedMainFileEOF) {
if (UsingPCHThroughHeader)
Diag(SourceLocation(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 1;
- else if (!PPOpts->PCHWithHdrStopCreate)
+ << PPOpts.PCHThroughHeader << 1;
+ else if (!PPOpts.PCHWithHdrStopCreate)
Diag(SourceLocation(), diag::err_pp_pragma_hdrstop_not_seen);
}
}
diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 48db9d46180ab..19074d7dcfdd4 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -60,11 +60,10 @@ class MacroExpansionContextTest : public ::testing::Test {
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
HeaderSearchOptions HSOpts;
TrivialModuleLoader ModLoader;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, Target.get());
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
auto Ctx = std::make_unique<MacroExpansionContext>(LangOpts);
diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp
index 1f2dba6fcc5d8..201c3f9a68d1d 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -136,12 +136,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
SourceMgr.setMainFileID(mainFileID);
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup =*/nullptr, /*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
@@ -186,12 +185,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithTokenSplit) {
SourceMgr.createFileID(llvm::MemoryBuffer::getMemBuffer(main)));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
llvm::SmallString<8> Scratch;
@@ -462,11 +460,10 @@ TEST_F(SourceManagerTest, ResetsIncludeLocMap) {
auto ParseFile = [&] {
TrivialModuleLoader ModLoader;
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
PP.LexTokensUntilEOF();
@@ -538,13 +535,12 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
// Ensure we can get expanded locations in presence of implicit includes.
// These are different than normal includes since predefines buffer doesn't
// have a valid insertion location.
@@ -657,12 +653,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
std::vector<MacroAction> Macros;
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang...
[truncated]
|
|
@llvm/pr-subscribers-clang-tidy Author: Jan Svoboda (jansvoboda11) ChangesThis PR makes it so that Patch is 29.02 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/133467.diff 17 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index a15850cb63542..03a3e8404e069 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -89,15 +89,14 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
HeaderInfo = std::make_unique<HeaderSearch>(HSOpts, Sources, Diags, LangOpts,
&Compiler.getTarget());
- auto PO = std::make_shared<PreprocessorOptions>();
- *PO = Compiler.getPreprocessorOpts();
-
- PP = std::make_unique<clang::Preprocessor>(PO, Diags, LangOpts, Sources,
- *HeaderInfo, ModuleLoader,
- /*IILookup=*/nullptr,
- /*OwnsHeaderSearch=*/false);
+ PP = std::make_unique<clang::Preprocessor>(Compiler.getPreprocessorOpts(),
+ Diags, LangOpts, Sources,
+ *HeaderInfo, ModuleLoader,
+ /*IILookup=*/nullptr,
+ /*OwnsHeaderSearch=*/false);
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
- InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
+ InitializePreprocessor(*PP, Compiler.getPreprocessorOpts(),
+ Compiler.getPCHContainerReader(),
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
Compiler.getTarget().getTriple());
diff --git a/clang-tools-extra/clangd/ModulesBuilder.cpp b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 03c5f5e1b5993..c1878f91b5e16 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -202,9 +202,10 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
/*Target=*/nullptr);
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModuleLoader;
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), *Diags, LangOpts,
- SourceMgr, HeaderInfo, ModuleLoader);
+ Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
+ ModuleLoader);
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
PCHContainerOperations PCHOperations;
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 1e4d2da86c2be..f71d27813b2a1 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -272,9 +272,6 @@ class CompilerInvocation : public CompilerInvocationBase {
std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() {
return HSOpts;
}
- std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
- return PPOpts;
- }
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
/// @}
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 4fdc4e0439125..24bb524783e93 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -140,7 +140,7 @@ class Preprocessor {
friend class VariadicMacroScopeGuard;
llvm::unique_function<void(const clang::Token &)> OnToken;
- std::shared_ptr<const PreprocessorOptions> PPOpts;
+ const PreprocessorOptions &PPOpts;
DiagnosticsEngine *Diags;
const LangOptions &LangOpts;
const TargetInfo *Target = nullptr;
@@ -1165,10 +1165,9 @@ class Preprocessor {
void updateOutOfDateIdentifier(const IdentifierInfo &II) const;
public:
- Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
- DiagnosticsEngine &diags, const LangOptions &LangOpts,
- SourceManager &SM, HeaderSearch &Headers,
- ModuleLoader &TheModuleLoader,
+ Preprocessor(const PreprocessorOptions &PPOpts, DiagnosticsEngine &diags,
+ const LangOptions &LangOpts, SourceManager &SM,
+ HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup = nullptr,
bool OwnsHeaderSearch = false,
TranslationUnitKind TUKind = TU_Complete);
@@ -1195,9 +1194,8 @@ class Preprocessor {
/// Cleanup after model file parsing
void FinalizeForModelFile();
- /// Retrieve the preprocessor options used to initialize this
- /// preprocessor.
- const PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
+ /// Retrieve the preprocessor options used to initialize this preprocessor.
+ const PreprocessorOptions &getPreprocessorOpts() const { return PPOpts; }
DiagnosticsEngine &getDiagnostics() const { return *Diags; }
void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 0a5f1cfd1a264..04ddc93415507 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -844,7 +844,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
HeaderSearch &HeaderInfo = *AST->HeaderInfo;
AST->PP = std::make_shared<Preprocessor>(
- AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
+ *AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
AST->getSourceManager(), HeaderInfo, AST->ModuleLoader,
/*IILookup=*/nullptr,
/*OwnsHeaderSearch=*/false);
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 91093d3ccb84c..9cab17ae70eeb 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -452,7 +452,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
HeaderSearch *HeaderInfo =
new HeaderSearch(getHeaderSearchOpts(), getSourceManager(),
getDiagnostics(), getLangOpts(), &getTarget());
- PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOptsPtr(),
+ PP = std::make_shared<Preprocessor>(Invocation->getPreprocessorOpts(),
getDiagnostics(), getLangOpts(),
getSourceManager(), *HeaderInfo, *this,
/*IdentifierInfoLookup=*/nullptr,
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index a29b73f97ab7e..0b53524e23641 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1154,7 +1154,7 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool isAngled, bool OpenFile,
}
}
- for (const auto &Entry : PPOpts->EmbedEntries) {
+ for (const auto &Entry : PPOpts.EmbedEntries) {
LookupPath.clear();
SeparateComponents(LookupPath, Entry, Filename, false);
llvm::Expected<FileEntryRef> ShouldBeEntry = FM.getFileRef(
@@ -2341,7 +2341,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
enum { Enter, Import, Skip, IncludeLimitReached } Action = Enter;
- if (PPOpts->SingleFileParseMode)
+ if (PPOpts.SingleFileParseMode)
Action = IncludeLimitReached;
// If we've reached the max allowed include depth, it is usually due to an
@@ -3420,11 +3420,11 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(DirectiveTok.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && !MI) {
+ if (PPOpts.SingleFileParseMode && !MI) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
@@ -3475,11 +3475,11 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
IfToken.getLocation(), DER.ExprRange,
(ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(IfToken.getLocation());
// Should we include the stuff contained by this directive?
- if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
+ if (PPOpts.SingleFileParseMode && DER.IncludedUndefinedIds) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
@@ -3546,10 +3546,10 @@ void Preprocessor::HandleElseDirective(Token &Result, const Token &HashToken) {
if (Callbacks)
Callbacks->Else(Result.getLocation(), CI.IfLoc);
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(Result.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false,
@@ -3626,10 +3626,10 @@ void Preprocessor::HandleElifFamilyDirective(Token &ElifToken,
}
}
- bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
+ bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
getSourceManager().isInMainFile(ElifToken.getLocation());
- if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
+ if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
// the directive blocks.
CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index e1dcc5499170e..a373a52506a24 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -561,7 +561,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
// Reached the end of the compilation without finding the through header.
Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 0;
+ << PPOpts.PCHThroughHeader << 0;
}
if (!isIncrementalProcessingEnabled())
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index ff99575dc611b..c25a3efd899e0 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -77,13 +77,13 @@ LLVM_INSTANTIATE_REGISTRY(PragmaHandlerRegistry)
ExternalPreprocessorSource::~ExternalPreprocessorSource() = default;
-Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
+Preprocessor::Preprocessor(const PreprocessorOptions &PPOpts,
DiagnosticsEngine &diags, const LangOptions &opts,
SourceManager &SM, HeaderSearch &Headers,
ModuleLoader &TheModuleLoader,
IdentifierInfoLookup *IILookup, bool OwnsHeaders,
TranslationUnitKind TUKind)
- : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts),
+ : PPOpts(PPOpts), Diags(&diags), LangOpts(opts),
FileMgr(Headers.getFileMgr()), SourceMgr(SM),
ScratchBuf(new ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
@@ -156,11 +156,11 @@ Preprocessor::Preprocessor(std::shared_ptr<const PreprocessorOptions> PPOpts,
SkippingUntilPragmaHdrStop = true;
// If using a PCH with a through header, start skipping tokens.
- if (!this->PPOpts->PCHThroughHeader.empty() &&
- !this->PPOpts->ImplicitPCHInclude.empty())
+ if (!this->PPOpts.PCHThroughHeader.empty() &&
+ !this->PPOpts.ImplicitPCHInclude.empty())
SkippingUntilPCHThroughHeader = true;
- if (this->PPOpts->GeneratePreamble)
+ if (this->PPOpts.GeneratePreamble)
PreambleConditionalStack.startRecording();
MaxTokens = LangOpts.MaxTokens;
@@ -577,18 +577,18 @@ void Preprocessor::EnterMainSourceFile() {
// Start parsing the predefines.
EnterSourceFile(FID, nullptr, SourceLocation());
- if (!PPOpts->PCHThroughHeader.empty()) {
+ if (!PPOpts.PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
OptionalFileEntryRef File = LookupFile(
- SourceLocation(), PPOpts->PCHThroughHeader,
+ SourceLocation(), PPOpts.PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr,
/*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
/*SuggestedModule=*/nullptr, /*IsMapped=*/nullptr,
/*IsFrameworkFound=*/nullptr);
if (!File) {
Diag(SourceLocation(), diag::err_pp_through_header_not_found)
- << PPOpts->PCHThroughHeader;
+ << PPOpts.PCHThroughHeader;
return;
}
setPCHThroughHeaderFileID(
@@ -614,21 +614,21 @@ bool Preprocessor::isPCHThroughHeader(const FileEntry *FE) {
}
bool Preprocessor::creatingPCHWithThroughHeader() {
- return TUKind == TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind == TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::usingPCHWithThroughHeader() {
- return TUKind != TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
+ return TUKind != TU_Prefix && !PPOpts.PCHThroughHeader.empty() &&
PCHThroughHeaderFileID.isValid();
}
bool Preprocessor::creatingPCHWithPragmaHdrStop() {
- return TUKind == TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind == TU_Prefix && PPOpts.PCHWithHdrStop;
}
bool Preprocessor::usingPCHWithPragmaHdrStop() {
- return TUKind != TU_Prefix && PPOpts->PCHWithHdrStop;
+ return TUKind != TU_Prefix && PPOpts.PCHWithHdrStop;
}
/// Skip tokens until after the #include of the through header or
@@ -657,8 +657,8 @@ void Preprocessor::SkipTokensWhileUsingPCH() {
if (ReachedMainFileEOF) {
if (UsingPCHThroughHeader)
Diag(SourceLocation(), diag::err_pp_through_header_not_seen)
- << PPOpts->PCHThroughHeader << 1;
- else if (!PPOpts->PCHWithHdrStopCreate)
+ << PPOpts.PCHThroughHeader << 1;
+ else if (!PPOpts.PCHWithHdrStopCreate)
Diag(SourceLocation(), diag::err_pp_pragma_hdrstop_not_seen);
}
}
diff --git a/clang/unittests/Analysis/MacroExpansionContextTest.cpp b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
index 48db9d46180ab..19074d7dcfdd4 100644
--- a/clang/unittests/Analysis/MacroExpansionContextTest.cpp
+++ b/clang/unittests/Analysis/MacroExpansionContextTest.cpp
@@ -60,11 +60,10 @@ class MacroExpansionContextTest : public ::testing::Test {
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
HeaderSearchOptions HSOpts;
TrivialModuleLoader ModLoader;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, Target.get());
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
auto Ctx = std::make_unique<MacroExpansionContext>(LangOpts);
diff --git a/clang/unittests/Basic/SourceManagerTest.cpp b/clang/unittests/Basic/SourceManagerTest.cpp
index 1f2dba6fcc5d8..201c3f9a68d1d 100644
--- a/clang/unittests/Basic/SourceManagerTest.cpp
+++ b/clang/unittests/Basic/SourceManagerTest.cpp
@@ -136,12 +136,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnit) {
SourceMgr.setMainFileID(mainFileID);
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup =*/nullptr, /*OwnsHeaderSearch =*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
@@ -186,12 +185,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithTokenSplit) {
SourceMgr.createFileID(llvm::MemoryBuffer::getMemBuffer(main)));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
llvm::SmallString<8> Scratch;
@@ -462,11 +460,10 @@ TEST_F(SourceManagerTest, ResetsIncludeLocMap) {
auto ParseFile = [&] {
TrivialModuleLoader ModLoader;
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
PP.EnterMainSourceFile();
PP.LexTokensUntilEOF();
@@ -538,13 +535,12 @@ TEST_F(SourceManagerTest, getMacroArgExpandedLocation) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
// Ensure we can get expanded locations in presence of implicit includes.
// These are different than normal includes since predefines buffer doesn't
// have a valid insertion location.
@@ -657,12 +653,11 @@ TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) {
SourceMgr.overrideFileContents(headerFile, std::move(HeaderBuf));
HeaderSearchOptions HSOpts;
+ PreprocessorOptions PPOpts;
TrivialModuleLoader ModLoader;
HeaderSearch HeaderInfo(HSOpts, SourceMgr, Diags, LangOpts, &*Target);
- Preprocessor PP(std::make_shared<PreprocessorOptions>(), Diags, LangOpts,
- SourceMgr, HeaderInfo, ModLoader,
- /*IILookup =*/nullptr,
- /*OwnsHeaderSearch =*/false);
+ Preprocessor PP(PPOpts, Diags, LangOpts, SourceMgr, HeaderInfo, ModLoader,
+ /*IILookup=*/nullptr, /*OwnsHeaderSearch=*/false);
PP.Initialize(*Target);
std::vector<MacroAction> Macros;
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang...
[truncated]
|
You can test this locally with the following command:git-clang-format --diff 277ab85d1ccf80750f5193495c0665808c2863de 9348867cfb2d243df7e91f20d6e635217d9af4e1 --extensions h,cpp -- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp clang-tools-extra/clangd/ModulesBuilder.cpp clang/include/clang/Frontend/CompilerInvocation.h clang/include/clang/Lex/Preprocessor.h clang/lib/Frontend/ASTUnit.cpp clang/lib/Frontend/CompilerInstance.cpp clang/lib/Lex/PPDirectives.cpp clang/lib/Lex/PPLexerChange.cpp clang/lib/Lex/Preprocessor.cpp clang/unittests/Analysis/MacroExpansionContextTest.cpp clang/unittests/Basic/SourceManagerTest.cpp clang/unittests/Lex/LexerTest.cpp clang/unittests/Lex/ModuleDeclStateTest.cpp clang/unittests/Lex/PPCallbacksTest.cpp clang/unittests/Lex/PPConditionalDirectiveRecordTest.cpp clang/unittests/Lex/PPDependencyDirectivesTest.cpp clang/unittests/Lex/PPMemoryAllocationsTest.cppView the diff from clang-format here.diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 0b53524e23..866488ff83 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -3420,8 +3420,9 @@ void Preprocessor::HandleIfdefDirective(Token &Result,
Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
}
- bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
- getSourceManager().isInMainFile(DirectiveTok.getLocation());
+ bool RetainExcludedCB =
+ PPOpts.RetainExcludedConditionalBlocks &&
+ getSourceManager().isInMainFile(DirectiveTok.getLocation());
// Should we include the stuff contained by this directive?
if (PPOpts.SingleFileParseMode && !MI) {
@@ -3475,8 +3476,9 @@ void Preprocessor::HandleIfDirective(Token &IfToken,
IfToken.getLocation(), DER.ExprRange,
(ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False));
- bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
- getSourceManager().isInMainFile(IfToken.getLocation());
+ bool RetainExcludedCB =
+ PPOpts.RetainExcludedConditionalBlocks &&
+ getSourceManager().isInMainFile(IfToken.getLocation());
// Should we include the stuff contained by this directive?
if (PPOpts.SingleFileParseMode && DER.IncludedUndefinedIds) {
@@ -3547,7 +3549,7 @@ void Preprocessor::HandleElseDirective(Token &Result, const Token &HashToken) {
Callbacks->Else(Result.getLocation(), CI.IfLoc);
bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
- getSourceManager().isInMainFile(Result.getLocation());
+ getSourceManager().isInMainFile(Result.getLocation());
if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
@@ -3626,8 +3628,9 @@ void Preprocessor::HandleElifFamilyDirective(Token &ElifToken,
}
}
- bool RetainExcludedCB = PPOpts.RetainExcludedConditionalBlocks &&
- getSourceManager().isInMainFile(ElifToken.getLocation());
+ bool RetainExcludedCB =
+ PPOpts.RetainExcludedConditionalBlocks &&
+ getSourceManager().isInMainFile(ElifToken.getLocation());
if ((PPOpts.SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
// In 'single-file-parse mode' undefined identifiers trigger parsing of all
|
|
Are you planning to do the same for LangOpts and HSOpts? What's the ultimate goal here? There's also this comment on Which only makes sense if these |
Yes, I'd like to do this for all options. The immediate goal is for We can use this to avoid making copies of the entire invocation when compiling a chain of implicit modules, for example. But more importantly, once we know there are no mutable references to My idea is that the build system creates one common invocation for a build target and then passes that to the dependency scanner along with any file-specific options. This not only saves time of re-running the driver and re-parsing command lines, but also enables deduplicating the construction of the dependency graph, which we currently do in full for each TU. Note that we can't just use the strict context hash for this deduplication, since we care about the canonical command lines. This should change the complexity of creating dependency graphs from (roughly)
Yeah, I think this is mostly used in |
benlangmuir
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great, thanks for explaining!
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/22000 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/2836 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/23911 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/27880 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/20906 Here is the relevant piece of the build log for the reference |
…7680) This PR makes `CompilerInvocation` the sole owner of the `AnalyzerOptions` instance. Clients can no longer become co-owners by doing something like this: ```c++ void shareOwnership(CompilerInvocation &CI) { IntrusiveRefCntPtr Shared = &CI.getAnalyzerOpts(); } ``` The motivation for this is given here: #133467 (comment)
…m#137680) This PR makes `CompilerInvocation` the sole owner of the `AnalyzerOptions` instance. Clients can no longer become co-owners by doing something like this: ```c++ void shareOwnership(CompilerInvocation &CI) { IntrusiveRefCntPtr Shared = &CI.getAnalyzerOpts(); } ``` The motivation for this is given here: llvm#133467 (comment)
…rusive (#137680)
This PR makes `CompilerInvocation` the sole owner of the
`AnalyzerOptions` instance. Clients can no longer become co-owners by
doing something like this:
```c++
void shareOwnership(CompilerInvocation &CI) {
IntrusiveRefCntPtr Shared = &CI.getAnalyzerOpts();
}
```
The motivation for this is given here:
llvm/llvm-project#133467 (comment)
…m#137680) This PR makes `CompilerInvocation` the sole owner of the `AnalyzerOptions` instance. Clients can no longer become co-owners by doing something like this: ```c++ void shareOwnership(CompilerInvocation &CI) { IntrusiveRefCntPtr Shared = &CI.getAnalyzerOpts(); } ``` The motivation for this is given here: llvm#133467 (comment)
This PR makes it so that
CompilerInvocationis the sole owner of thePreprocessorOptionsinstance.