Skip to content

Commit d544174

Browse files
committed
Do not store CodeGenOptions on Preprocessor
1 parent 9039837 commit d544174

29 files changed

+135
-118
lines changed

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
9090
&Compiler.getTarget());
9191

9292
PP = std::make_unique<clang::Preprocessor>(Compiler.getPreprocessorOpts(),
93-
Diags, LangOpts, CGOpts, Sources,
93+
Diags, LangOpts, Sources,
9494
*HeaderInfo, ModuleLoader,
9595
/*IILookup=*/nullptr,
9696
/*OwnsHeaderSearch=*/false);
9797
PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
9898
InitializePreprocessor(*PP, Compiler.getPreprocessorOpts(),
9999
Compiler.getPCHContainerReader(),
100-
Compiler.getFrontendOpts());
100+
Compiler.getFrontendOpts(), Compiler.getCodeGenOpts());
101101
ApplyHeaderSearchOptions(*HeaderInfo, HSOpts, LangOpts,
102102
Compiler.getTarget().getTriple());
103103
}

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
131131
DiagnosticOptions DiagOpts;
132132
DiagnosticsEngine Diags;
133133
LangOptions LangOpts;
134-
CodeGenOptions CGOpts;
135134
HeaderSearchOptions HSOpts;
136135
TrivialModuleLoader ModuleLoader;
137136

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
194194

195195
LangOptions LangOpts;
196196
LangOpts.SkipODRCheckInGMF = true;
197-
CodeGenOptions CGOpts;
198197

199198
FileManager FileMgr(FileSystemOptions(), VFS);
200199

@@ -205,13 +204,14 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
205204

206205
PreprocessorOptions PPOpts;
207206
TrivialModuleLoader ModuleLoader;
208-
Preprocessor PP(PPOpts, *Diags, LangOpts, CGOpts, SourceMgr, HeaderInfo,
207+
Preprocessor PP(PPOpts, *Diags, LangOpts, SourceMgr, HeaderInfo,
209208
ModuleLoader);
210209

211210
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
212211
PCHContainerOperations PCHOperations;
212+
CodeGenOptions CodeGenOpts;
213213
ASTReader Reader(PP, *ModCache, /*ASTContext=*/nullptr,
214-
PCHOperations.getRawReader(), {});
214+
PCHOperations.getRawReader(), CodeGenOpts, {});
215215

216216
// We don't need any listener here. By default it will use a validator
217217
// listener.

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ASTContext;
6262
class ASTDeserializationListener;
6363
class ASTMutationListener;
6464
class ASTReader;
65+
class CodeGenOptions;
6566
class CompilerInstance;
6667
class CompilerInvocation;
6768
class Decl;
@@ -107,7 +108,7 @@ class ASTUnit {
107108

108109
private:
109110
std::unique_ptr<LangOptions> LangOpts;
110-
std::unique_ptr<CodeGenOptions> CGOpts = std::make_unique<CodeGenOptions>();
111+
std::unique_ptr<CodeGenOptions> CodeGenOpts;
111112
// FIXME: The documentation on \c LoadFrom* member functions states that the
112113
// DiagnosticsEngine (and therefore DiagnosticOptions) must outlive the
113114
// returned ASTUnit. This is not the case. Enfore it by storing non-owning

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ class CompilerInstance : public ModuleLoader {
720720
DisableValidationForModuleKind DisableValidation,
721721
bool AllowPCHWithCompilerErrors, Preprocessor &PP, ModuleCache &ModCache,
722722
ASTContext &Context, const PCHContainerReader &PCHContainerRdr,
723+
const CodeGenOptions &CodeGenOpts,
723724
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
724725
ArrayRef<std::shared_ptr<DependencyCollector>> DependencyCollectors,
725726
void *DeserializationListener, bool OwnDeserializationListener,

clang/include/clang/Frontend/Utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class CodeGenOptions;
4949
/// environment ready to process a single file.
5050
void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions &PPOpts,
5151
const PCHContainerReader &PCHContainerRdr,
52-
const FrontendOptions &FEOpts);
52+
const FrontendOptions &FEOpts,
53+
const CodeGenOptions &CodeGenOptions);
5354

5455
/// DoPrintPreprocessedInput - Implement -E mode.
5556
void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,

clang/include/clang/Lex/Preprocessor.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_CLANG_LEX_PREPROCESSOR_H
1515
#define LLVM_CLANG_LEX_PREPROCESSOR_H
1616

17-
#include "clang/Basic/CodeGenOptions.h"
1817
#include "clang/Basic/Diagnostic.h"
1918
#include "clang/Basic/DiagnosticIDs.h"
2019
#include "clang/Basic/IdentifierTable.h"
@@ -156,7 +155,6 @@ class Preprocessor {
156155
const PreprocessorOptions &PPOpts;
157156
DiagnosticsEngine *Diags;
158157
const LangOptions &LangOpts;
159-
const CodeGenOptions &CGOpts;
160158
const TargetInfo *Target = nullptr;
161159
const TargetInfo *AuxTarget = nullptr;
162160
FileManager &FileMgr;
@@ -1183,9 +1181,8 @@ class Preprocessor {
11831181

11841182
public:
11851183
Preprocessor(const PreprocessorOptions &PPOpts, DiagnosticsEngine &diags,
1186-
const LangOptions &LangOpts, const CodeGenOptions &CGOPts,
1187-
SourceManager &SM, HeaderSearch &Headers,
1188-
ModuleLoader &TheModuleLoader,
1184+
const LangOptions &LangOpts, SourceManager &SM,
1185+
HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
11891186
IdentifierInfoLookup *IILookup = nullptr,
11901187
bool OwnsHeaderSearch = false,
11911188
TranslationUnitKind TUKind = TU_Complete);
@@ -1219,7 +1216,6 @@ class Preprocessor {
12191216
void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
12201217

12211218
const LangOptions &getLangOpts() const { return LangOpts; }
1222-
const CodeGenOptions &getCodeGenOpts() const { return CGOpts; }
12231219
const TargetInfo &getTargetInfo() const { return *Target; }
12241220
const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
12251221
FileManager &getFileManager() const { return FileMgr; }

clang/include/clang/Serialization/ASTReader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ class ASTReader
509509
/// The AST consumer.
510510
ASTConsumer *Consumer = nullptr;
511511

512+
/// The codegen options.
513+
const CodeGenOptions &CodeGenOpts;
514+
512515
/// The module manager which manages modules and their dependencies
513516
ModuleManager ModuleMgr;
514517

@@ -1797,6 +1800,7 @@ class ASTReader
17971800
/// deserializing.
17981801
ASTReader(Preprocessor &PP, ModuleCache &ModCache, ASTContext *Context,
17991802
const PCHContainerReader &PCHContainerRdr,
1803+
const CodeGenOptions &CodeGenOpts,
18001804
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
18011805
StringRef isysroot = "",
18021806
DisableValidationForModuleKind DisableValidationKind =
@@ -1815,6 +1819,7 @@ class ASTReader
18151819
SourceManager &getSourceManager() const { return SourceMgr; }
18161820
FileManager &getFileManager() const { return FileMgr; }
18171821
DiagnosticsEngine &getDiags() const { return Diags; }
1822+
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
18181823

18191824
/// Flags that indicate what kind of AST loading failures the client
18201825
/// of the AST reader can directly handle.

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace clang {
4949
class ASTContext;
5050
class ASTReader;
5151
class Attr;
52+
class CodeGenOptions;
5253
class CXXRecordDecl;
5354
class FileEntry;
5455
class FPOptionsOverride;
@@ -124,6 +125,8 @@ class ASTWriter : public ASTDeserializationListener,
124125
/// The PCM manager which manages memory buffers for pcm files.
125126
ModuleCache &ModCache;
126127

128+
const CodeGenOptions &CodeGenOpts;
129+
127130
/// The preprocessor we're writing.
128131
Preprocessor *PP = nullptr;
129132

@@ -686,13 +689,14 @@ class ASTWriter : public ASTDeserializationListener,
686689
/// Create a new precompiled header writer that outputs to
687690
/// the given bitstream.
688691
ASTWriter(llvm::BitstreamWriter &Stream, SmallVectorImpl<char> &Buffer,
689-
ModuleCache &ModCache,
692+
ModuleCache &ModCache, const CodeGenOptions &CodeGenOpts,
690693
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
691694
bool IncludeTimestamps = true, bool BuildingImplicitModule = false,
692695
bool GeneratingReducedBMI = false);
693696
~ASTWriter() override;
694697

695698
const LangOptions &getLangOpts() const;
699+
const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
696700

697701
/// Get a timestamp for output into the AST file. The actual timestamp
698702
/// of the specified file may be ignored if we have been instructed to not
@@ -999,6 +1003,7 @@ class PCHGenerator : public SemaConsumer {
9991003
public:
10001004
PCHGenerator(Preprocessor &PP, ModuleCache &ModCache, StringRef OutputFile,
10011005
StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer,
1006+
const CodeGenOptions &CodeGenOpts,
10021007
ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
10031008
bool AllowASTWithErrors = false, bool IncludeTimestamps = true,
10041009
bool BuildingImplicitModule = false,
@@ -1021,13 +1026,14 @@ class CXX20ModulesGenerator : public PCHGenerator {
10211026
virtual Module *getEmittingModule(ASTContext &Ctx) override;
10221027

10231028
CXX20ModulesGenerator(Preprocessor &PP, ModuleCache &ModCache,
1024-
StringRef OutputFile, bool GeneratingReducedBMI,
1025-
bool AllowASTWithErrors);
1029+
StringRef OutputFile, const CodeGenOptions &CodeGenOpts,
1030+
bool GeneratingReducedBMI, bool AllowASTWithErrors);
10261031

10271032
public:
10281033
CXX20ModulesGenerator(Preprocessor &PP, ModuleCache &ModCache,
1029-
StringRef OutputFile, bool AllowASTWithErrors = false)
1030-
: CXX20ModulesGenerator(PP, ModCache, OutputFile,
1034+
StringRef OutputFile, const CodeGenOptions &CodeGenOpts,
1035+
bool AllowASTWithErrors = false)
1036+
: CXX20ModulesGenerator(PP, ModCache, OutputFile, CodeGenOpts,
10311037
/*GeneratingReducedBMI=*/false,
10321038
AllowASTWithErrors) {}
10331039

@@ -1039,8 +1045,9 @@ class ReducedBMIGenerator : public CXX20ModulesGenerator {
10391045

10401046
public:
10411047
ReducedBMIGenerator(Preprocessor &PP, ModuleCache &ModCache,
1042-
StringRef OutputFile, bool AllowASTWithErrors = false)
1043-
: CXX20ModulesGenerator(PP, ModCache, OutputFile,
1048+
StringRef OutputFile, const CodeGenOptions &CodeGenOpts,
1049+
bool AllowASTWithErrors = false)
1050+
: CXX20ModulesGenerator(PP, ModCache, OutputFile, CodeGenOpts,
10441051
/*GeneratingReducedBMI=*/true,
10451052
AllowASTWithErrors) {}
10461053
};

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
995995
std::vector<std::unique_ptr<ASTConsumer>> Consumers(2);
996996
Consumers[0] = std::make_unique<ReducedBMIGenerator>(
997997
CI.getPreprocessor(), CI.getModuleCache(),
998-
CI.getFrontendOpts().ModuleOutputPath);
998+
CI.getFrontendOpts().ModuleOutputPath, CI.getCodeGenOpts());
999999
Consumers[1] = std::move(Result);
10001000
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
10011001
}

0 commit comments

Comments
 (0)