Skip to content

Commit 69049bf

Browse files
committed
[clang][modules] Serialize CodeGenOptions
1 parent 499e656 commit 69049bf

28 files changed

+386
-148
lines changed

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
209209

210210
IntrusiveRefCntPtr<ModuleCache> ModCache = createCrossProcessModuleCache();
211211
PCHContainerOperations PCHOperations;
212+
CodeGenOptions CodeGenOpts;
212213
ASTReader Reader(PP, *ModCache, /*ASTContext=*/nullptr,
213-
PCHOperations.getRawReader(), {});
214+
PCHOperations.getRawReader(), CodeGenOpts, {});
214215

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

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,17 @@ CODEGENOPT(ObjCAvoidHeapifyLocalBlocks, 1, 0, Benign)
209209

210210

211211
// The optimization options affect frontend options, which in turn do affect the AST.
212-
VALUE_CODEGENOPT(OptimizationLevel, 2, 0, Affecting) ///< The -O[0-3] option specified.
213-
VALUE_CODEGENOPT(OptimizeSize, 2, 0, Affecting) ///< If -Os (==1, Benign) or -Oz (==2, Benign) is specified.
212+
VALUE_CODEGENOPT(OptimizationLevel, 2, 0, Compatible) ///< The -O[0-3] option specified.
213+
VALUE_CODEGENOPT(OptimizeSize, 2, 0, Compatible) ///< If -Os (==1, Benign) or -Oz (==2, Benign) is specified.
214214

215215
CODEGENOPT(AtomicProfileUpdate , 1, 0, Benign) ///< Set -fprofile-update=atomic
216216
CODEGENOPT(ContinuousProfileSync, 1, 0, Benign) ///< Enable continuous instrumentation profiling
217217
/// Choose profile instrumenation kind or no instrumentation.
218218

219-
ENUM_CODEGENOPT(ProfileInstr, llvm::driver::ProfileInstrKind, 4, llvm::driver::ProfileInstrKind::ProfileNone, Benign)
219+
ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 4, ProfileInstrKind::ProfileNone, Benign)
220220

221221
/// Choose profile kind for PGO use compilation.
222-
ENUM_CODEGENOPT(ProfileUse, llvm::driver::ProfileInstrKind, 2, llvm::driver::ProfileInstrKind::ProfileNone, Benign)
222+
ENUM_CODEGENOPT(ProfileUse, ProfileInstrKind, 2, ProfileInstrKind::ProfileNone, Benign)
223223
/// Partition functions into N groups and select only functions in group i to be
224224
/// instrumented. Selected group numbers can be 0 to N-1 inclusive.
225225
VALUE_CODEGENOPT(ProfileTotalFunctionGroups, 32, 1, Benign)
@@ -244,8 +244,8 @@ CODEGENOPT(SaveTempLabels , 1, 0, Benign) ///< Save temporary labels.
244244
CODEGENOPT(SanitizeAddressUseAfterScope , 1, 0, Benign) ///< Enable use-after-scope detection
245245
///< in AddressSanitizer
246246
ENUM_CODEGENOPT(SanitizeAddressUseAfterReturn,
247-
llvm::AsanDetectStackUseAfterReturnMode, 2,
248-
llvm::AsanDetectStackUseAfterReturnMode::Runtime,
247+
AsanDetectStackUseAfterReturnMode, 2,
248+
AsanDetectStackUseAfterReturnMode::Runtime,
249249
Benign
250250
) ///< Set detection mode for stack-use-after-return.
251251
CODEGENOPT(SanitizeAddressPoisonCustomArrayCookie, 1, 0, Benign) ///< Enable poisoning operator new[] which is not a replaceable
@@ -255,9 +255,9 @@ CODEGENOPT(SanitizeAddressGlobalsDeadStripping, 1, 0, Benign) ///< Enable linker
255255
CODEGENOPT(SanitizeAddressUseOdrIndicator, 1, 0, Benign) ///< Enable ODR indicator globals
256256
CODEGENOPT(SanitizeMemoryTrackOrigins, 2, 0, Benign) ///< Enable tracking origins in
257257
///< MemorySanitizer
258-
ENUM_CODEGENOPT(SanitizeAddressDtor, llvm::AsanDtorKind, 2,
259-
llvm::AsanDtorKind::Global, Benign) ///< Set how ASan global
260-
///< destructors are emitted.
258+
ENUM_CODEGENOPT(SanitizeAddressDtor, AsanDtorKind, 2,
259+
AsanDtorKind::Global, Benign) ///< Set how ASan global
260+
///< destructors are emitted.
261261
CODEGENOPT(SanitizeMemoryParamRetval, 1, 0, Benign) ///< Enable detection of uninitialized
262262
///< parameters and return values
263263
///< in MemorySanitizer
@@ -375,13 +375,13 @@ VALUE_CODEGENOPT(SmallDataLimit, 32, 0, Benign)
375375
VALUE_CODEGENOPT(SSPBufferSize, 32, 0, Benign)
376376

377377
/// The kind of inlining to perform.
378-
ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining, Benign)
378+
ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining, Compatible)
379379

380380
/// The maximum stack size a function can have to be considered for inlining.
381381
VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX, Benign)
382382

383383
// Vector functions library to use.
384-
ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 4, llvm::driver::VectorLibrary::NoLibrary, Benign)
384+
ENUM_CODEGENOPT(VecLib, VectorLibrary, 4, VectorLibrary::NoLibrary, Benign)
385385

386386
/// The default TLS model to use.
387387
ENUM_CODEGENOPT(DefaultTLSModel, TLSModel, 2, GeneralDynamicTLSModel, Benign)
@@ -457,8 +457,8 @@ ENUM_CODEGENOPT(SwiftAsyncFramePointer, SwiftAsyncFramePointerKind, 2,
457457
CODEGENOPT(SkipRaxSetup, 1, 0, Benign)
458458

459459
/// Whether to zero out caller-used registers before returning.
460-
ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
461-
5, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind::Skip, Benign)
460+
ENUM_CODEGENOPT(ZeroCallUsedRegs, ZeroCallUsedRegsKind,
461+
5, ZeroCallUsedRegsKind::Skip, Benign)
462462

463463
/// Modify C++ ABI to returning `this` pointer from constructors and
464464
/// non-deleting destructors. (No effect on Microsoft ABI.)
@@ -477,8 +477,8 @@ CODEGENOPT(ResMayAlias, 1, 0, Benign)
477477

478478
/// Controls how unwind v2 (epilog) information should be generated for x64
479479
/// Windows.
480-
ENUM_CODEGENOPT(WinX64EHUnwindV2, llvm::WinX64EHUnwindV2Mode,
481-
2, llvm::WinX64EHUnwindV2Mode::Disabled, Benign)
480+
ENUM_CODEGENOPT(WinX64EHUnwindV2, WinX64EHUnwindV2Mode,
481+
2, WinX64EHUnwindV2Mode::Disabled, Benign)
482482

483483
/// FIXME: Make DebugOptions its own top-level .def file.
484484
#include "DebugOptions.def"

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,31 @@ class CodeGenOptionsBase {
4646
enum class CompatibilityKind {
4747
/// Does affect the construction of the AST in a way that does prevent
4848
/// module interoperability.
49-
Affecting,
49+
NotCompatible,
50+
/// Does affect the construction of the AST in a way that doesn't prevent
51+
/// interoperability (that is, the value can be different between an
52+
/// explicit module and the user of that module).
53+
Compatible,
5054
/// Does not affect the construction of the AST in any way (that is, the
5155
/// value can be different between an implicit module and the user of that
5256
/// module).
5357
Benign,
5458
};
5559

60+
using CFBranchLabelSchemeKind = CFBranchLabelSchemeKind;
61+
using ProfileInstrKind = llvm::driver::ProfileInstrKind;
62+
using AsanDetectStackUseAfterReturnMode = llvm::AsanDetectStackUseAfterReturnMode;
63+
using AsanDtorKind = llvm::AsanDtorKind;
64+
using VectorLibrary = llvm::driver::VectorLibrary;
65+
using ZeroCallUsedRegsKind = llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind;
66+
using WinX64EHUnwindV2Mode = llvm::WinX64EHUnwindV2Mode;
67+
68+
using DebugCompressionType = llvm::DebugCompressionType;
69+
using EmitDwarfUnwindType = llvm::EmitDwarfUnwindType;
70+
using DebugTemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind;
71+
using DebugInfoKind = llvm::codegenoptions::DebugInfoKind;
72+
using DebuggerKind = llvm::DebuggerKind;
73+
5674
#define CODEGENOPT(Name, Bits, Default, Compatibility) unsigned Name : Bits;
5775
#define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility)
5876
#include "clang/Basic/CodeGenOptions.def"

clang/include/clang/Basic/DebugOptions.def

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ VALUE_CODEGENOPT(Name, Bits, Default, Compatibility)
2828
ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility)
2929
#endif
3030

31-
ENUM_DEBUGOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
32-
llvm::DebugCompressionType::None, Benign)
33-
DEBUGOPT(Dwarf64, 1, 0, Affecting) ///< -gdwarf64.
31+
ENUM_DEBUGOPT(CompressDebugSections, DebugCompressionType, 2,
32+
DebugCompressionType::None, Benign)
33+
DEBUGOPT(Dwarf64, 1, 0, Compatible) ///< -gdwarf64.
3434
DEBUGOPT(EnableDIPreservationVerify, 1, 0, Benign) ///< Enable di preservation
3535
///< verify each (it means
3636
///< check the original debug
@@ -40,17 +40,17 @@ DEBUGOPT(ForceDwarfFrameSection , 1, 0, Benign) ///< Set when -fforce-dwarf-fram
4040
///< is enabled.
4141

4242
///< Set when -femit-dwarf-unwind is passed.
43-
ENUM_DEBUGOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
44-
llvm::EmitDwarfUnwindType::Default, Benign)
43+
ENUM_DEBUGOPT(EmitDwarfUnwind, EmitDwarfUnwindType, 2,
44+
EmitDwarfUnwindType::Default, Benign)
4545

4646
DEBUGOPT(NoDwarfDirectoryAsm , 1, 0, Benign) ///< Set when -fno-dwarf-directory-asm
4747
///< is enabled.
4848

4949
DEBUGOPT(NoInlineLineTables, 1, 0, Benign) ///< Whether debug info should contain
5050
///< inline line tables.
5151

52-
DEBUGOPT(DebugStrictDwarf, 1, 1, Affecting) ///< Whether or not to use strict DWARF info.
53-
DEBUGOPT(DebugOmitUnreferencedMethods, 1, 0, Affecting) ///< Omit unreferenced member
52+
DEBUGOPT(DebugStrictDwarf, 1, 1, Compatible) ///< Whether or not to use strict DWARF info.
53+
DEBUGOPT(DebugOmitUnreferencedMethods, 1, 0, Compatible) ///< Omit unreferenced member
5454
///< functions in type debug info.
5555

5656
/// Control the Assignment Tracking debug info feature.
@@ -60,73 +60,73 @@ ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,
6060
/// Whether or not to use Key Instructions to determine breakpoint locations.
6161
DEBUGOPT(DebugKeyInstructions, 1, 0, Benign)
6262

63-
DEBUGOPT(DebugColumnInfo, 1, 0, Affecting) ///< Whether or not to use column information
63+
DEBUGOPT(DebugColumnInfo, 1, 0, Compatible) ///< Whether or not to use column information
6464
///< in debug info.
6565

66-
DEBUGOPT(DebugTypeExtRefs, 1, 0, Affecting) ///< Whether or not debug info should contain
66+
DEBUGOPT(DebugTypeExtRefs, 1, 0, Compatible) ///< Whether or not debug info should contain
6767
///< external references to a PCH or module.
6868

69-
DEBUGOPT(DebugExplicitImport, 1, 0, Affecting) ///< Whether or not debug info should
69+
DEBUGOPT(DebugExplicitImport, 1, 0, Compatible) ///< Whether or not debug info should
7070
///< contain explicit imports for
7171
///< anonymous namespaces
7272

7373
/// Set debug info source file hashing algorithm.
74-
ENUM_DEBUGOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5, Affecting)
74+
ENUM_DEBUGOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5, Compatible)
7575

76-
DEBUGOPT(SplitDwarfInlining, 1, 1, Affecting) ///< Whether to include inlining info in the
76+
DEBUGOPT(SplitDwarfInlining, 1, 1, Compatible) ///< Whether to include inlining info in the
7777
///< skeleton CU to allow for symbolication
7878
///< of inline stack frames without .dwo files.
79-
DEBUGOPT(DebugFwdTemplateParams, 1, 0, Affecting) ///< Whether to emit complete
79+
DEBUGOPT(DebugFwdTemplateParams, 1, 0, Compatible) ///< Whether to emit complete
8080
///< template parameter descriptions in
8181
///< forward declarations (versus just
8282
///< including them in the name).
8383
ENUM_DEBUGOPT(DebugSimpleTemplateNames,
84-
llvm::codegenoptions::DebugTemplateNamesKind, 2,
85-
llvm::codegenoptions::DebugTemplateNamesKind::Full, Affecting)
84+
DebugTemplateNamesKind, 2,
85+
DebugTemplateNamesKind::Full, Compatible)
8686
///< Whether to emit template parameters in the textual names of
8787
///< template specializations.
8888
///< Implies DebugFwdTemplateNames to allow decorated names to be
8989
///< reconstructed when needed.
9090

9191
/// The kind of generated debug info.
92-
ENUM_DEBUGOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4,
93-
llvm::codegenoptions::NoDebugInfo, Affecting)
92+
ENUM_DEBUGOPT(DebugInfo, DebugInfoKind, 4,
93+
DebugInfoKind::NoDebugInfo, Compatible)
9494

9595
/// Whether to generate macro debug info.
96-
DEBUGOPT(MacroDebugInfo, 1, 0, Affecting)
96+
DEBUGOPT(MacroDebugInfo, 1, 0, Compatible)
9797

9898
/// Tune the debug info for this debugger.
99-
ENUM_DEBUGOPT(DebuggerTuning, llvm::DebuggerKind, 3,
100-
llvm::DebuggerKind::Default, Affecting)
99+
ENUM_DEBUGOPT(DebuggerTuning, DebuggerKind, 3,
100+
DebuggerKind::Default, Compatible)
101101

102102
/// Dwarf version. Version zero indicates to LLVM that no DWARF should be
103103
/// emitted.
104-
VALUE_DEBUGOPT(DwarfVersion, 3, 0, Affecting)
104+
VALUE_DEBUGOPT(DwarfVersion, 3, 0, Compatible)
105105

106106
/// Whether we should emit CodeView debug information. It's possible to emit
107107
/// CodeView and DWARF into the same object.
108-
DEBUGOPT(EmitCodeView, 1, 0, Affecting)
108+
DEBUGOPT(EmitCodeView, 1, 0, Compatible)
109109

110110
/// Whether to emit the .debug$H section containing hashes of CodeView types.
111-
DEBUGOPT(CodeViewGHash, 1, 0, Affecting)
111+
DEBUGOPT(CodeViewGHash, 1, 0, Compatible)
112112

113113
/// Whether to emit the compiler path and command line into the CodeView debug information.
114-
DEBUGOPT(CodeViewCommandLine, 1, 0, Affecting)
114+
DEBUGOPT(CodeViewCommandLine, 1, 0, Compatible)
115115

116116
/// Whether emit extra debug info for sample pgo profile collection.
117-
DEBUGOPT(DebugInfoForProfiling, 1, 0, Affecting)
117+
DEBUGOPT(DebugInfoForProfiling, 1, 0, Compatible)
118118

119119
/// Whether to emit DW_TAG_template_alias for template aliases.
120-
DEBUGOPT(DebugTemplateAlias, 1, 0, Affecting)
120+
DEBUGOPT(DebugTemplateAlias, 1, 0, Compatible)
121121

122122
/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
123-
DEBUGOPT(DebugNameTable, 2, 0, Affecting)
123+
DEBUGOPT(DebugNameTable, 2, 0, Compatible)
124124

125125
/// Whether to use DWARF base address specifiers in .debug_ranges.
126-
DEBUGOPT(DebugRangesBaseAddress, 1, 0, Affecting)
126+
DEBUGOPT(DebugRangesBaseAddress, 1, 0, Compatible)
127127

128128
/// Whether to embed source in DWARF debug line section.
129-
DEBUGOPT(EmbedSource, 1, 0, Affecting)
129+
DEBUGOPT(EmbedSource, 1, 0, Compatible)
130130

131131
#undef DEBUGOPT
132132
#undef ENUM_DEBUGOPT

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def err_ast_file_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in
4141
"precompiled file '%3' but is currently %select{disabled|enabled}2">;
4242
def err_ast_file_langopt_value_mismatch : Error<
4343
"%0 differs in precompiled file '%1' vs. current file">;
44+
def err_ast_file_codegenopt_mismatch : Error<"%0 was %select{disabled|enabled}1 in "
45+
"precompiled file '%3' but is currently %select{disabled|enabled}2">;
46+
def err_ast_file_codegenopt_value_mismatch
47+
: Error<"%0 differs in precompiled file '%1' vs. current file">;
4448
def err_ast_file_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
4549
"the precompiled file '%1'">;
4650
def err_ast_file_modulecache_mismatch : Error<"precompiled file '%2' was compiled with module cache "

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ LANGOPT(ModulesValidateTextualHeaderIncludes, 1, 1, Compatible, "validation of t
161161
LANGOPT(ModulesErrorRecovery, 1, 1, Benign, "automatically importing modules as needed when performing error recovery")
162162
LANGOPT(ImplicitModules, 1, 1, Benign, "building modules that are not specified via -fmodule-file")
163163
LANGOPT(ModulesLocalVisibility, 1, 0, Compatible, "local submodule visibility")
164-
LANGOPT(Optimize , 1, 0, Compatible, "__OPTIMIZE__ predefined macro")
165-
LANGOPT(OptimizeSize , 1, 0, Compatible, "__OPTIMIZE_SIZE__ predefined macro")
166164
LANGOPT(Static , 1, 0, Compatible, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")
167165
VALUE_LANGOPT(PackStruct , 32, 0, NotCompatible,
168166
"default struct packing maximum alignment")
@@ -179,7 +177,6 @@ VALUE_LANGOPT(PIE , 1, 0, Compatible, "is pie")
179177
LANGOPT(ROPI , 1, 0, NotCompatible, "Read-only position independence")
180178
LANGOPT(RWPI , 1, 0, NotCompatible, "Read-write position independence")
181179
LANGOPT(GNUInline , 1, 0, Compatible, "GNU inline semantics")
182-
LANGOPT(NoInlineDefine , 1, 0, Compatible, "__NO_INLINE__ predefined macro")
183180
LANGOPT(Deprecated , 1, 0, Compatible, "__DEPRECATED predefined macro")
184181
LANGOPT(FastMath , 1, 0, Compatible, "fast FP math optimizations, and __FAST_MATH__ predefined macro")
185182
LANGOPT(UnsafeFPMath , 1, 0, Compatible, "Unsafe Floating Point Math")

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 2 additions & 0 deletions
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,6 +108,7 @@ class ASTUnit {
107108

108109
private:
109110
std::unique_ptr<LangOptions> LangOpts;
111+
std::unique_ptr<CodeGenOptions> CodeGenOpts;
110112
// FIXME: The documentation on \c LoadFrom* member functions states that the
111113
// DiagnosticsEngine (and therefore DiagnosticOptions) must outlive the
112114
// 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/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace serialization {
4444
/// Version 4 of AST files also requires that the version control branch and
4545
/// revision match exactly, since there is no backward compatibility of
4646
/// AST files at this time.
47-
const unsigned VERSION_MAJOR = 34;
47+
const unsigned VERSION_MAJOR = 35;
4848

4949
/// AST file minor version number supported by this version of
5050
/// Clang.
@@ -399,6 +399,9 @@ enum OptionsRecordTypes {
399399

400400
/// Record code for the preprocessor options table.
401401
PREPROCESSOR_OPTIONS,
402+
403+
/// Record code for the codegen options table.
404+
CODEGEN_OPTIONS,
402405
};
403406

404407
/// Record codes for the unhashed control block.

0 commit comments

Comments
 (0)