Skip to content

Commit 42465f4

Browse files
committed
DebugInfo: (NFC) Refactor DWARF version calculation to make a future change (-fdebug-default-version) easier
1 parent 96bb076 commit 42465f4

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,11 +3198,16 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
31983198
}
31993199

32003200
// If a -gdwarf argument appeared, remember it.
3201-
if (const Arg *A =
3201+
const Arg *GDwarfN =
32023202
Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
3203-
options::OPT_gdwarf_4, options::OPT_gdwarf_5))
3204-
if (checkDebugInfoOption(A, Args, D, TC))
3205-
DWARFVersion = DwarfVersionNum(A->getSpelling());
3203+
options::OPT_gdwarf_4, options::OPT_gdwarf_5);
3204+
bool EmitDwarf = false;
3205+
if (GDwarfN) {
3206+
if (checkDebugInfoOption(GDwarfN, Args, D, TC))
3207+
EmitDwarf = true;
3208+
else
3209+
GDwarfN = nullptr;
3210+
}
32063211

32073212
if (const Arg *A = Args.getLastArg(options::OPT_gcodeview)) {
32083213
if (checkDebugInfoOption(A, Args, D, TC))
@@ -3211,18 +3216,28 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
32113216

32123217
// If the user asked for debug info but did not explicitly specify -gcodeview
32133218
// or -gdwarf, ask the toolchain for the default format.
3214-
if (!EmitCodeView && DWARFVersion == 0 &&
3219+
if (!EmitCodeView && !EmitDwarf &&
32153220
DebugInfoKind != codegenoptions::NoDebugInfo) {
32163221
switch (TC.getDefaultDebugFormat()) {
32173222
case codegenoptions::DIF_CodeView:
32183223
EmitCodeView = true;
32193224
break;
32203225
case codegenoptions::DIF_DWARF:
3221-
DWARFVersion = TC.GetDefaultDwarfVersion();
3226+
EmitDwarf = true;
32223227
break;
32233228
}
32243229
}
32253230

3231+
if (EmitDwarf) {
3232+
// Start with the platform default DWARF version
3233+
DWARFVersion = TC.GetDefaultDwarfVersion();
3234+
3235+
// Override with a user-specified DWARF version
3236+
if (GDwarfN)
3237+
if (auto ExplicitVersion = DwarfVersionNum(GDwarfN->getSpelling()))
3238+
DWARFVersion = ExplicitVersion;
3239+
}
3240+
32263241
// -gline-directives-only supported only for the DWARF debug info.
32273242
if (DWARFVersion == 0 && DebugInfoKind == codegenoptions::DebugDirectivesOnly)
32283243
DebugInfoKind = codegenoptions::NoDebugInfo;

0 commit comments

Comments
 (0)