Skip to content

Commit 3dfa76e

Browse files
committed
[clang] Serialize CodeGenOptions
Some `LangOptions` duplicate their `CodeGenOptions` counterparts. My understanding is that this was done solely because some infrastructure (like serialization, module compatibility checks, etc.) were only implemented for `LangOptions`. This PR starts adds support for `CodeGenOptions`, serializes them into AST files and implements compatibility checking, which allows deduplicating some of these fields.
1 parent d1ba269 commit 3dfa76e

30 files changed

+322
-168
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
// that have enumeration type and VALUE_CODEGENOPT is a code
1313
// generation option that describes a value rather than a flag.
1414
//
15-
// AFFECTING_VALUE_CODEGENOPT is used for code generation options that can
16-
// affect the AST.
15+
// COMPATIBLE_VALUE_CODEGENOPT is used for code generation options that affect
16+
// the construction of the AST in a way that doesn't prevent
17+
// interoperability (that is, the value can be different between an explicit
18+
// module and the user of that module).
1719
//
1820
//===----------------------------------------------------------------------===//
1921
#ifndef CODEGENOPT
@@ -30,11 +32,16 @@ CODEGENOPT(Name, Bits, Default)
3032
CODEGENOPT(Name, Bits, Default)
3133
#endif
3234

33-
#ifndef AFFECTING_VALUE_CODEGENOPT
34-
# define AFFECTING_VALUE_CODEGENOPT(Name, Bits, Default) \
35+
#ifndef COMPATIBLE_VALUE_CODEGENOPT
36+
# define COMPATIBLE_VALUE_CODEGENOPT(Name, Bits, Default, Description) \
3537
VALUE_CODEGENOPT(Name, Bits, Default)
3638
#endif
3739

40+
#ifndef COMPATIBLE_ENUM_CODEGENOPT
41+
# define COMPATIBLE_ENUM_CODEGENOPT(Name, Type, Bits, Default, Description) \
42+
ENUM_CODEGENOPT(Name, Type, Bits, Default)
43+
#endif
44+
3845
CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
3946
CODEGENOPT(Crel, 1, 0) ///< -Wa,--crel
4047
CODEGENOPT(ImplicitMapSyms, 1, 0) ///< -Wa,-mmapsyms=implicit
@@ -216,9 +223,9 @@ CODEGENOPT(ObjCConvertMessagesToRuntimeCalls , 1, 1)
216223
CODEGENOPT(ObjCAvoidHeapifyLocalBlocks, 1, 0)
217224

218225

219-
// The optimization options affect frontend options, whicn in turn do affect the AST.
220-
AFFECTING_VALUE_CODEGENOPT(OptimizationLevel, 2, 0) ///< The -O[0-3] option specified.
221-
AFFECTING_VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified.
226+
// The optimization options affect frontend options, which in turn do affect the AST.
227+
COMPATIBLE_VALUE_CODEGENOPT(OptimizationLevel, 2, 0, "optimization level") ///< The -O[0-3] option specified.
228+
COMPATIBLE_VALUE_CODEGENOPT(OptimizeSize, 2, 0, "optimizing for size") ///< If -Os (==1) or -Oz (==2) is specified.
222229

223230
CODEGENOPT(AtomicProfileUpdate , 1, 0) ///< Set -fprofile-update=atomic
224231
CODEGENOPT(ContinuousProfileSync, 1, 0) ///< Enable continuous instrumentation profiling
@@ -383,7 +390,7 @@ VALUE_CODEGENOPT(SmallDataLimit, 32, 0)
383390
VALUE_CODEGENOPT(SSPBufferSize, 32, 0)
384391

385392
/// The kind of inlining to perform.
386-
ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)
393+
COMPATIBLE_ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining, "inlining kind")
387394

388395
/// The maximum stack size a function can have to be considered for inlining.
389396
VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX)
@@ -494,4 +501,5 @@ ENUM_CODEGENOPT(WinX64EHUnwindV2, llvm::WinX64EHUnwindV2Mode,
494501
#undef CODEGENOPT
495502
#undef ENUM_CODEGENOPT
496503
#undef VALUE_CODEGENOPT
497-
#undef AFFECTING_VALUE_CODEGENOPT
504+
#undef COMPATIBLE_VALUE_CODEGENOPT
505+
#undef COMPATIBLE_ENUM_CODEGENOPT

clang/include/clang/Basic/DiagnosticSerializationKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ 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_value_mismatch
45+
: Error<"%0 differs in precompiled file '%1' vs. current file">;
4446
def err_ast_file_diagopt_mismatch : Error<"%0 is currently enabled, but was not in "
4547
"the precompiled file '%1'">;
4648
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
@@ -206,8 +206,6 @@ COMPATIBLE_LANGOPT(ModulesValidateTextualHeaderIncludes, 1, 1, "validation of te
206206
BENIGN_LANGOPT(ModulesErrorRecovery, 1, 1, "automatically importing modules as needed when performing error recovery")
207207
BENIGN_LANGOPT(ImplicitModules, 1, 1, "building modules that are not specified via -fmodule-file")
208208
COMPATIBLE_LANGOPT(ModulesLocalVisibility, 1, 0, "local submodule visibility")
209-
COMPATIBLE_LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro")
210-
COMPATIBLE_LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro")
211209
COMPATIBLE_LANGOPT(Static , 1, 0, "__STATIC__ predefined macro (as opposed to __DYNAMIC__)")
212210
VALUE_LANGOPT(PackStruct , 32, 0,
213211
"default struct packing maximum alignment")
@@ -224,7 +222,6 @@ COMPATIBLE_VALUE_LANGOPT(PIE , 1, 0, "is pie")
224222
LANGOPT(ROPI , 1, 0, "Read-only position independence")
225223
LANGOPT(RWPI , 1, 0, "Read-write position independence")
226224
COMPATIBLE_LANGOPT(GNUInline , 1, 0, "GNU inline semantics")
227-
COMPATIBLE_LANGOPT(NoInlineDefine , 1, 0, "__NO_INLINE__ predefined macro")
228225
COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro")
229226
COMPATIBLE_LANGOPT(FastMath , 1, 0, "fast FP math optimizations, and __FAST_MATH__ predefined macro")
230227
COMPATIBLE_LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math")

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ASTUnit {
107107

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

clang/include/clang/Frontend/Utils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ 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,
53-
const CodeGenOptions &CodeGenOpts);
52+
const FrontendOptions &FEOpts);
5453

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

clang/include/clang/Lex/Preprocessor.h

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

17+
#include "clang/Basic/CodeGenOptions.h"
1718
#include "clang/Basic/Diagnostic.h"
1819
#include "clang/Basic/DiagnosticIDs.h"
1920
#include "clang/Basic/IdentifierTable.h"
@@ -155,6 +156,7 @@ class Preprocessor {
155156
const PreprocessorOptions &PPOpts;
156157
DiagnosticsEngine *Diags;
157158
const LangOptions &LangOpts;
159+
const CodeGenOptions &CGOpts;
158160
const TargetInfo *Target = nullptr;
159161
const TargetInfo *AuxTarget = nullptr;
160162
FileManager &FileMgr;
@@ -1181,8 +1183,9 @@ class Preprocessor {
11811183

11821184
public:
11831185
Preprocessor(const PreprocessorOptions &PPOpts, DiagnosticsEngine &diags,
1184-
const LangOptions &LangOpts, SourceManager &SM,
1185-
HeaderSearch &Headers, ModuleLoader &TheModuleLoader,
1186+
const LangOptions &LangOpts, const CodeGenOptions &CGOPts,
1187+
SourceManager &SM, HeaderSearch &Headers,
1188+
ModuleLoader &TheModuleLoader,
11861189
IdentifierInfoLookup *IILookup = nullptr,
11871190
bool OwnsHeaderSearch = false,
11881191
TranslationUnitKind TUKind = TU_Complete);
@@ -1216,6 +1219,7 @@ class Preprocessor {
12161219
void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
12171220

12181221
const LangOptions &getLangOpts() const { return LangOpts; }
1222+
const CodeGenOptions &getCodeGenOpts() const { return CGOpts; }
12191223
const TargetInfo &getTargetInfo() const { return *Target; }
12201224
const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
12211225
FileManager &getFileManager() const { return FileMgr; }

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.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class ASTContext;
7272
class ASTDeserializationListener;
7373
class ASTReader;
7474
class ASTRecordReader;
75+
class CodeGenOptions;
7576
class CXXTemporary;
7677
class Decl;
7778
class DeclarationName;
@@ -137,6 +138,15 @@ class ASTReaderListener {
137138
return false;
138139
}
139140

141+
/// Receives the codegen options.
142+
///
143+
/// \returns true to indicate the options are invalid or false otherwise.
144+
virtual bool ReadCodeGenOptions(const CodeGenOptions &CGOpts,
145+
StringRef ModuleFilename, bool Complain,
146+
bool AllowCompatibleDifferences) {
147+
return false;
148+
}
149+
140150
/// Receives the target options.
141151
///
142152
/// \returns true to indicate the target options are invalid, or false
@@ -281,6 +291,9 @@ class ChainedASTReaderListener : public ASTReaderListener {
281291
bool ReadLanguageOptions(const LangOptions &LangOpts,
282292
StringRef ModuleFilename, bool Complain,
283293
bool AllowCompatibleDifferences) override;
294+
bool ReadCodeGenOptions(const CodeGenOptions &CGOpts,
295+
StringRef ModuleFilename, bool Complain,
296+
bool AllowCompatibleDifferences) override;
284297
bool ReadTargetOptions(const TargetOptions &TargetOpts,
285298
StringRef ModuleFilename, bool Complain,
286299
bool AllowCompatibleDifferences) override;
@@ -322,6 +335,9 @@ class PCHValidator : public ASTReaderListener {
322335
bool ReadLanguageOptions(const LangOptions &LangOpts,
323336
StringRef ModuleFilename, bool Complain,
324337
bool AllowCompatibleDifferences) override;
338+
bool ReadCodeGenOptions(const CodeGenOptions &CGOpts,
339+
StringRef ModuleFilename, bool Complain,
340+
bool AllowCompatibleDifferences) override;
325341
bool ReadTargetOptions(const TargetOptions &TargetOpts,
326342
StringRef ModuleFilename, bool Complain,
327343
bool AllowCompatibleDifferences) override;
@@ -1586,6 +1602,10 @@ class ASTReader
15861602
StringRef ModuleFilename, bool Complain,
15871603
ASTReaderListener &Listener,
15881604
bool AllowCompatibleDifferences);
1605+
static bool ParseCodeGenOptions(const RecordData &Record,
1606+
StringRef ModuleFilename, bool Complain,
1607+
ASTReaderListener &Listener,
1608+
bool AllowCompatibleDifferences);
15891609
static bool ParseTargetOptions(const RecordData &Record,
15901610
StringRef ModuleFilename, bool Complain,
15911611
ASTReaderListener &Listener,
@@ -1996,14 +2016,12 @@ class ASTReader
19962016

19972017
/// Determine whether the given AST file is acceptable to load into a
19982018
/// translation unit with the given language and target options.
1999-
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
2000-
const ModuleCache &ModCache,
2001-
const PCHContainerReader &PCHContainerRdr,
2002-
const LangOptions &LangOpts,
2003-
const TargetOptions &TargetOpts,
2004-
const PreprocessorOptions &PPOpts,
2005-
StringRef ExistingModuleCachePath,
2006-
bool RequireStrictOptionMatches = false);
2019+
static bool isAcceptableASTFile(
2020+
StringRef Filename, FileManager &FileMgr, const ModuleCache &ModCache,
2021+
const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts,
2022+
const CodeGenOptions &CGOpts, const TargetOptions &TargetOpts,
2023+
const PreprocessorOptions &PPOpts, StringRef ExistingModuleCachePath,
2024+
bool RequireStrictOptionMatches = false);
20072025

20082026
/// Returns the suggested contents of the predefines buffer,
20092027
/// which contains a (typically-empty) subset of the predefines

clang/lib/Basic/CodeGenOptions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
2626
#define CODEGENOPT(Name, Bits, Default) Name = Default;
2727
#define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default);
2828
// Do not reset AST affecting code generation options.
29-
#define AFFECTING_VALUE_CODEGENOPT(Name, Bits, Default)
29+
#define COMPATIBLE_VALUE_CODEGENOPT(Name, Bits, Default, Description)
30+
#define COMPATIBLE_ENUM_CODEGENOPT(Name, Type, Bits, Default, Description)
3031
#include "clang/Basic/CodeGenOptions.def"
3132

3233
// Next reset all debug options that can always be reset, because they never

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,8 @@ void CGDebugInfo::CreateCompileUnit() {
797797
// Create new compile unit.
798798
TheCU = DBuilder.createCompileUnit(
799799
LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer : "",
800-
LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
800+
CGOpts.OptimizationLevel != 0 || CGOpts.PrepareForLTO ||
801+
CGOpts.PrepareForThinLTO,
801802
CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
802803
DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
803804
NameTableKind, CGOpts.DebugRangesBaseAddress, remapDIPath(Sysroot), SDK);
@@ -2273,7 +2274,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
22732274
Flags |= llvm::DINode::FlagRValueReference;
22742275
if (!Method->isExternallyVisible())
22752276
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
2276-
if (CGM.getLangOpts().Optimize)
2277+
if (CGM.getCodeGenOpts().OptimizationLevel != 0)
22772278
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
22782279

22792280
// In this debug mode, emit type info for a class when its constructor type
@@ -4344,7 +4345,7 @@ llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
43444345
FD->getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
43454346
if (!FD->isExternallyVisible())
43464347
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4347-
if (CGM.getLangOpts().Optimize)
4348+
if (CGM.getCodeGenOpts().OptimizationLevel != 0)
43484349
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
43494350

43504351
if (Stub) {
@@ -4664,7 +4665,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, SourceLocation Loc,
46644665

46654666
if (Fn->hasLocalLinkage())
46664667
SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4667-
if (CGM.getLangOpts().Optimize)
4668+
if (CGM.getCodeGenOpts().OptimizationLevel != 0)
46684669
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
46694670

46704671
llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
@@ -4747,7 +4748,7 @@ void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,
47474748
unsigned LineNo = getLineNumber(Loc);
47484749
unsigned ScopeLine = 0;
47494750
llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4750-
if (CGM.getLangOpts().Optimize)
4751+
if (CGM.getCodeGenOpts().OptimizationLevel != 0)
47514752
SPFlags |= llvm::DISubprogram::SPFlagOptimized;
47524753

47534754
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
@@ -5079,7 +5080,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
50795080
// Use VarDecl's Tag, Scope and Line number.
50805081
auto FieldAlign = getDeclAlignIfRequired(Field, CGM.getContext());
50815082
auto *D = DBuilder.createAutoVariable(
5082-
Scope, FieldName, Unit, Line, FieldTy, CGM.getLangOpts().Optimize,
5083+
Scope, FieldName, Unit, Line, FieldTy,
5084+
CGM.getCodeGenOpts().OptimizationLevel != 0,
50835085
Flags | llvm::DINode::FlagArtificial, FieldAlign);
50845086

50855087
// Insert an llvm.dbg.declare into the current block.
@@ -5105,9 +5107,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
51055107
llvm::DILocalVariable *D = nullptr;
51065108
if (ArgNo) {
51075109
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5108-
D = DBuilder.createParameterVariable(Scope, Name, *ArgNo, Unit, Line, Ty,
5109-
CGM.getLangOpts().Optimize, Flags,
5110-
Annotations);
5110+
D = DBuilder.createParameterVariable(
5111+
Scope, Name, *ArgNo, Unit, Line, Ty,
5112+
CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
51115113
} else {
51125114
// For normal local variable, we will try to find out whether 'VD' is the
51135115
// copy parameter of coroutine.
@@ -5148,8 +5150,9 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
51485150
D = RemapCoroArgToLocalVar();
51495151
// Or we will create a new DIVariable for this Decl if D dose not exists.
51505152
if (!D)
5151-
D = DBuilder.createAutoVariable(Scope, Name, Unit, Line, Ty,
5152-
CGM.getLangOpts().Optimize, Flags, Align);
5153+
D = DBuilder.createAutoVariable(
5154+
Scope, Name, Unit, Line, Ty,
5155+
CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
51535156
}
51545157
// Insert an llvm.dbg.declare into the current block.
51555158
DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
@@ -5203,7 +5206,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
52035206
auto *Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
52045207
// Create the descriptor for the variable.
52055208
llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5206-
Scope, Name, Unit, Line, Ty, CGM.getLangOpts().Optimize,
5209+
Scope, Name, Unit, Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
52075210
llvm::DINode::FlagZero, Align);
52085211

52095212
if (const MemberExpr *ME = dyn_cast<MemberExpr>(BD->getBinding())) {
@@ -5301,8 +5304,8 @@ void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy &Builder) {
53015304
StringRef Name = D->getName();
53025305

53035306
// Create the descriptor for the label.
5304-
auto *L =
5305-
DBuilder.createLabel(Scope, Name, Unit, Line, CGM.getLangOpts().Optimize);
5307+
auto *L = DBuilder.createLabel(Scope, Name, Unit, Line,
5308+
CGM.getCodeGenOpts().OptimizationLevel != 0);
53065309

53075310
// Insert an llvm.dbg.label into the current block.
53085311
DBuilder.insertLabel(L,
@@ -5565,7 +5568,8 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
55655568

55665569
// Create the descriptor for the parameter.
55675570
auto *debugVar = DBuilder.createParameterVariable(
5568-
scope, Name, ArgNo, tunit, line, type, CGM.getLangOpts().Optimize, flags);
5571+
scope, Name, ArgNo, tunit, line, type,
5572+
CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
55695573

55705574
// Insert an llvm.dbg.declare into the current block.
55715575
DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
@@ -6340,7 +6344,7 @@ llvm::DebugLoc CGDebugInfo::SourceLocToDebugLoc(SourceLocation Loc) {
63406344
llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const {
63416345
// Call site-related attributes are only useful in optimized programs, and
63426346
// when there's a possibility of debugging backtraces.
6343-
if (!CGM.getLangOpts().Optimize ||
6347+
if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
63446348
DebugKind == llvm::codegenoptions::NoDebugInfo ||
63456349
DebugKind == llvm::codegenoptions::LocTrackingOnly)
63466350
return llvm::DINode::FlagZero;

0 commit comments

Comments
 (0)