Skip to content

Commit e79a45b

Browse files
committed
[clang][modules] Reset codegen options (take 2). (llvm#74388)
CodeGen options do not affect the AST, so they usually can be ignored. The only exception to the rule is when a PCM is created with `-gmodules`. In that case the Clang module format is switched to object file container and contains also serialized debug information that can be affected by debug options. There the following approach was choosen: 1.) Split out all the debug options into a separate `DebugOptions.def` file. The file is included by `CodeGenOptions.def`, so the change is transparent to all existing users of `CodeGenOptions.def`. 2.) Reset all CodeGen options, but excluding affecting debug options. 3.) Conditionally reset debug options that can affect the PCM. This fixes rdar://113135909. (cherry picked from commit 5ad3a32) Conflicts: clang/include/clang/Basic/CodeGenOptions.def
1 parent 44de7aa commit e79a45b

File tree

7 files changed

+263
-88
lines changed

7 files changed

+263
-88
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ CODEGENOPT(Name, Bits, Default)
2828
#endif
2929

3030
CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
31-
ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
32-
llvm::DebugCompressionType::None)
3331
CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
3432
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
35-
CODEGENOPT(Dwarf64 , 1, 0) ///< -gdwarf64.
36-
CODEGENOPT(Dwarf32 , 1, 1) ///< -gdwarf32.
3733
CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
3834
CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new
3935
CODEGENOPT(AssumeUniqueVTables , 1, 1) ///< Assume a class has only one vtable.
@@ -72,10 +68,6 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
7268
CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled.
7369
CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
7470
///< '-g' + 'O>0' level.
75-
CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
76-
///< each (it means check
77-
///< the original debug info
78-
///< metadata preservation).
7971
CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
8072
///< is specified.
8173
CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls.
@@ -112,16 +104,10 @@ CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix
112104
CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
113105
///< enabled.
114106
CODEGENOPT(StackSizeSection , 1, 0) ///< Set when -fstack-size-section is enabled.
115-
CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is
116-
///< enabled.
117107

118108
///< Set when -femit-compact-unwind-non-canonical is enabled.
119109
CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0)
120110

121-
///< Set when -femit-dwarf-unwind is passed.
122-
ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
123-
llvm::EmitDwarfUnwindType::Default)
124-
125111
///< Set when -fxray-always-emit-customevents is enabled.
126112
CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)
127113

@@ -177,17 +163,13 @@ CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
177163
CODEGENOPT(MergeFunctions , 1, 0) ///< Set when -fmerge-functions is enabled.
178164
CODEGENOPT(SplitColdCode , 1, 0) ///< Set when -fsplit-cold-code is enabled.
179165
CODEGENOPT(NoCommon , 1, 0) ///< Set when -fno-common or C++ is enabled.
180-
CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm is
181-
///< enabled.
182166
CODEGENOPT(NoExecStack , 1, 0) ///< Set when -Wa,--noexecstack is enabled.
183167
CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
184168
///< enabled.
185169
CODEGENOPT(NoWarn , 1, 0) ///< Set when -Wa,--no-warn is enabled.
186170
CODEGENOPT(NoTypeCheck , 1, 0) ///< Set when -Wa,--no-type-check is enabled.
187171
CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled
188172
CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled.
189-
CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
190-
///< inline line tables.
191173
CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection is enabled.
192174
CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled.
193175
CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is defined.
@@ -340,37 +322,6 @@ VALUE_CODEGENOPT(StackProbeSize , 32, 4096) ///< Overrides default stack
340322
///< probe size, even if 0.
341323
VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via -fwarn-stack-size.
342324
CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
343-
CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
344-
345-
/// Control the Assignment Tracking debug info feature.
346-
ENUM_CODEGENOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, AssignmentTrackingOpts::Disabled)
347-
348-
CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
349-
///< in debug info.
350-
351-
CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain
352-
///< external references to a PCH or module.
353-
354-
CODEGENOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info should
355-
///< contain explicit imports for
356-
///< anonymous namespaces
357-
358-
/// Set debug info source file hashing algorithm.
359-
ENUM_CODEGENOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5)
360-
361-
CODEGENOPT(SplitDwarfInlining, 1, 1) ///< Whether to include inlining info in the
362-
///< skeleton CU to allow for symbolication
363-
///< of inline stack frames without .dwo files.
364-
CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to emit complete
365-
///< template parameter descriptions in
366-
///< forward declarations (versus just
367-
///< including them in the name).
368-
ENUM_CODEGENOPT(DebugSimpleTemplateNames, llvm::codegenoptions::DebugTemplateNamesKind, 2, llvm::codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template parameters
369-
///< in the textual names of template
370-
///< specializations.
371-
///< Implies DebugFwdTemplateNames to
372-
///< allow decorated names to be
373-
///< reconstructed when needed.
374325
CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.
375326

376327
CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program
@@ -394,33 +345,6 @@ VALUE_CODEGENOPT(SmallDataLimit, 32, 0)
394345
/// The lower bound for a buffer to be considered for stack protection.
395346
VALUE_CODEGENOPT(SSPBufferSize, 32, 0)
396347

397-
/// The kind of generated debug info.
398-
ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, llvm::codegenoptions::NoDebugInfo)
399-
400-
/// Whether to make debug info reproducible.
401-
CODEGENOPT(ReproducibleDebugInfo, 1, 0)
402-
403-
/// Whether to generate macro debug info.
404-
CODEGENOPT(MacroDebugInfo, 1, 0)
405-
406-
/// Tune the debug info for this debugger.
407-
ENUM_CODEGENOPT(DebuggerTuning, llvm::DebuggerKind, 3,
408-
llvm::DebuggerKind::Default)
409-
410-
/// Dwarf version. Version zero indicates to LLVM that no DWARF should be
411-
/// emitted.
412-
VALUE_CODEGENOPT(DwarfVersion, 3, 0)
413-
414-
/// Whether we should emit CodeView debug information. It's possible to emit
415-
/// CodeView and DWARF into the same object.
416-
CODEGENOPT(EmitCodeView, 1, 0)
417-
418-
/// Whether to emit the .debug$H section containing hashes of CodeView types.
419-
CODEGENOPT(CodeViewGHash, 1, 0)
420-
421-
/// Whether to emit the compiler path and command line into the CodeView debug information.
422-
CODEGENOPT(CodeViewCommandLine, 1, 0)
423-
424348
/// The kind of inlining to perform.
425349
ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)
426350

@@ -453,26 +377,14 @@ CODEGENOPT(DirectAccessExternalData, 1, 0)
453377
/// paths that reach the end of a function without executing a required return.
454378
CODEGENOPT(StrictReturn, 1, 1)
455379

456-
/// Whether emit extra debug info for sample pgo profile collection.
457-
CODEGENOPT(DebugInfoForProfiling, 1, 0)
458-
459380
/// Whether emit pseudo probes for sample pgo profile collection.
460381
CODEGENOPT(PseudoProbeForProfiling, 1, 0)
461382

462383
/// Whether 3-component vector type is preserved.
463384
CODEGENOPT(PreserveVec3Type, 1, 0)
464385

465-
/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
466-
CODEGENOPT(DebugNameTable, 2, 0)
467-
468-
/// Whether to use DWARF base address specifiers in .debug_ranges.
469-
CODEGENOPT(DebugRangesBaseAddress, 1, 0)
470-
471386
CODEGENOPT(NoPLT, 1, 0)
472387

473-
/// Whether to embed source in DWARF debug line section.
474-
CODEGENOPT(EmbedSource, 1, 0)
475-
476388
/// Whether to emit all vtables
477389
CODEGENOPT(ForceEmitVTables, 1, 0)
478390

@@ -527,6 +439,9 @@ ENUM_CODEGENOPT(CASObjMode, llvm::CASBackendMode,
527439
/// non-deleting destructors. (No effect on Microsoft ABI.)
528440
CODEGENOPT(CtorDtorReturnThis, 1, 0)
529441

442+
/// FIXME: Make DebugOptions its own top-level .def file.
443+
#include "DebugOptions.def"
444+
530445
#undef CODEGENOPT
531446
#undef ENUM_CODEGENOPT
532447
#undef VALUE_CODEGENOPT

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
536536
return SanitizeBinaryMetadataCovered || SanitizeBinaryMetadataAtomics ||
537537
SanitizeBinaryMetadataUAR;
538538
}
539+
540+
/// Reset all of the options that are not considered when building a
541+
/// module.
542+
void resetNonModularOptions(StringRef ModuleFormat);
539543
};
540544

541545
} // end namespace clang
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
//===--- DebugOptions.def - Debug option database ----------------- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines debug-specific codegen options. Users of this file
10+
// must define the CODEGENOPT macro to make use of this information.
11+
// Optionally, the user may also define DEBUGOPT (for flags), ENUM_DEBUGOPT (for
12+
// options that have enumeration type), and VALUE_DEBUGOPT (is a debug option
13+
// that describes a value rather than a flag).
14+
//
15+
// BENIGN_ variants of the macros are used to describe options that do not
16+
// affect the generated PCM.
17+
//
18+
//===----------------------------------------------------------------------===//
19+
#ifndef DEBUGOPT
20+
#define DEBUGOPT(Name, Bits, Default) \
21+
CODEGENOPT(Name, Bits, Default)
22+
#endif
23+
24+
#ifndef VALUE_DEBUGOPT
25+
# define VALUE_DEBUGOPT(Name, Bits, Default) \
26+
VALUE_CODEGENOPT(Name, Bits, Default)
27+
#endif
28+
29+
#ifndef ENUM_DEBUGOPT
30+
# define ENUM_DEBUGOPT(Name, Type, Bits, Default) \
31+
ENUM_CODEGENOPT(Name, Type, Bits, Default)
32+
#endif
33+
34+
#ifndef BENIGN_DEBUGOPT
35+
#define BENIGN_DEBUGOPT(Name, Bits, Default) \
36+
DEBUGOPT(Name, Bits, Default)
37+
#endif
38+
39+
#ifndef BENIGN_VALUE_DEBUGOPT
40+
# define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default) \
41+
VALUE_DEBUGOPT(Name, Bits, Default)
42+
#endif
43+
44+
#ifndef BENIGN_ENUM_DEBUGOPT
45+
# define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default) \
46+
ENUM_DEBUGOPT(Name, Type, Bits, Default)
47+
#endif
48+
49+
BENIGN_ENUM_DEBUGOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
50+
llvm::DebugCompressionType::None)
51+
DEBUGOPT(Dwarf64, 1, 0) ///< -gdwarf64.
52+
BENIGN_DEBUGOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation
53+
///< verify each (it means
54+
///< check the original debug
55+
///< info metadata
56+
///< preservation).
57+
BENIGN_DEBUGOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame
58+
///< is enabled.
59+
60+
///< Set when -femit-dwarf-unwind is passed.
61+
BENIGN_ENUM_DEBUGOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
62+
llvm::EmitDwarfUnwindType::Default)
63+
64+
BENIGN_DEBUGOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm
65+
///< is enabled.
66+
67+
BENIGN_DEBUGOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
68+
///< inline line tables.
69+
70+
DEBUGOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
71+
72+
/// Control the Assignment Tracking debug info feature.
73+
BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,
74+
AssignmentTrackingOpts::Disabled)
75+
76+
DEBUGOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
77+
///< in debug info.
78+
79+
DEBUGOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain
80+
///< external references to a PCH or module.
81+
82+
DEBUGOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info should
83+
///< contain explicit imports for
84+
///< anonymous namespaces
85+
86+
/// Set debug info source file hashing algorithm.
87+
ENUM_DEBUGOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5)
88+
89+
DEBUGOPT(SplitDwarfInlining, 1, 1) ///< Whether to include inlining info in the
90+
///< skeleton CU to allow for symbolication
91+
///< of inline stack frames without .dwo files.
92+
DEBUGOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to emit complete
93+
///< template parameter descriptions in
94+
///< forward declarations (versus just
95+
///< including them in the name).
96+
ENUM_DEBUGOPT(DebugSimpleTemplateNames,
97+
llvm::codegenoptions::DebugTemplateNamesKind, 2,
98+
llvm::codegenoptions::DebugTemplateNamesKind::Full)
99+
///< Whether to emit template parameters in the textual names of
100+
///< template specializations.
101+
///< Implies DebugFwdTemplateNames to allow decorated names to be
102+
///< reconstructed when needed.
103+
104+
/// The kind of generated debug info.
105+
ENUM_DEBUGOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4,
106+
llvm::codegenoptions::NoDebugInfo)
107+
108+
/// Whether to make debug info reproducible.
109+
DEBUGOPT(ReproducibleDebugInfo, 1, 0)
110+
111+
/// Whether to generate macro debug info.
112+
DEBUGOPT(MacroDebugInfo, 1, 0)
113+
114+
/// Tune the debug info for this debugger.
115+
ENUM_DEBUGOPT(DebuggerTuning, llvm::DebuggerKind, 3,
116+
llvm::DebuggerKind::Default)
117+
118+
/// Dwarf version. Version zero indicates to LLVM that no DWARF should be
119+
/// emitted.
120+
VALUE_DEBUGOPT(DwarfVersion, 3, 0)
121+
122+
/// Whether we should emit CodeView debug information. It's possible to emit
123+
/// CodeView and DWARF into the same object.
124+
DEBUGOPT(EmitCodeView, 1, 0)
125+
126+
/// Whether to emit the .debug$H section containing hashes of CodeView types.
127+
DEBUGOPT(CodeViewGHash, 1, 0)
128+
129+
/// Whether to emit the compiler path and command line into the CodeView debug information.
130+
DEBUGOPT(CodeViewCommandLine, 1, 0)
131+
132+
/// Whether emit extra debug info for sample pgo profile collection.
133+
DEBUGOPT(DebugInfoForProfiling, 1, 0)
134+
135+
/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
136+
DEBUGOPT(DebugNameTable, 2, 0)
137+
138+
/// Whether to use DWARF base address specifiers in .debug_ranges.
139+
DEBUGOPT(DebugRangesBaseAddress, 1, 0)
140+
141+
/// Whether to embed source in DWARF debug line section.
142+
DEBUGOPT(EmbedSource, 1, 0)
143+
144+
#undef DEBUGOPT
145+
#undef ENUM_DEBUGOPT
146+
#undef VALUE_DEBUGOPT
147+
#undef BENIGN_DEBUGOPT
148+
#undef BENIGN_ENUM_DEBUGOPT
149+
#undef BENIGN_VALUE_DEBUGOPT

clang/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module Clang_Basic {
6565
textual header "clang/Basic/BuiltinsX86_64.def"
6666
textual header "clang/Basic/BuiltinsXCore.def"
6767
textual header "clang/Basic/CodeGenOptions.def"
68+
textual header "clang/Basic/DebugOptions.def"
6869
textual header "clang/Basic/DiagnosticOptions.def"
6970
textual header "clang/Basic/Features.def"
7071
textual header "clang/Basic/FPOptions.def"

clang/lib/Basic/CodeGenOptions.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,39 @@ CodeGenOptions::CodeGenOptions() {
2020
memcpy(CoverageVersion, "408*", 4);
2121
}
2222

23+
void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
24+
// First reset all CodeGen options only. The Debug options are handled later.
25+
#define DEBUGOPT(Name, Bits, Default)
26+
#define VALUE_DEBUGOPT(Name, Bits, Default)
27+
#define ENUM_DEBUGOPT(Name, Type, Bits, Default)
28+
#define CODEGENOPT(Name, Bits, Default) Name = Default;
29+
#define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default);
30+
#include "clang/Basic/CodeGenOptions.def"
31+
32+
// Next reset all debug options that can always be reset, because they never
33+
// affect the PCM.
34+
#define DEBUGOPT(Name, Bits, Default)
35+
#define VALUE_DEBUGOPT(Name, Bits, Default)
36+
#define ENUM_DEBUGOPT(Name, Type, Bits, Default)
37+
#define BENIGN_DEBUGOPT(Name, Bits, Default) Name = Default;
38+
#define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default) Name = Default;
39+
#define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default) set##Name(Default);
40+
#include "clang/Basic/DebugOptions.def"
41+
42+
// Conditionally reset debug options that only matter when the debug info is
43+
// emitted into the PCM (-gmodules).
44+
if (ModuleFormat == "raw" && !DebugTypeExtRefs) {
45+
#define DEBUGOPT(Name, Bits, Default) Name = Default;
46+
#define VALUE_DEBUGOPT(Name, Bits, Default) Name = Default;
47+
#define ENUM_DEBUGOPT(Name, Type, Bits, Default) set##Name(Default);
48+
#define BENIGN_DEBUGOPT(Name, Bits, Default)
49+
#define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default)
50+
#define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default)
51+
#include "clang/Basic/DebugOptions.def"
52+
}
53+
54+
RelocationModel = llvm::Reloc::PIC_;
55+
memcpy(CoverageVersion, "408*", 4);
56+
}
57+
2358
} // end namespace clang

0 commit comments

Comments
 (0)