@@ -3198,11 +3198,16 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
3198
3198
}
3199
3199
3200
3200
// If a -gdwarf argument appeared, remember it.
3201
- if ( const Arg *A =
3201
+ const Arg *GDwarfN =
3202
3202
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
+ }
3206
3211
3207
3212
if (const Arg *A = Args.getLastArg (options::OPT_gcodeview)) {
3208
3213
if (checkDebugInfoOption (A, Args, D, TC))
@@ -3211,18 +3216,28 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
3211
3216
3212
3217
// If the user asked for debug info but did not explicitly specify -gcodeview
3213
3218
// or -gdwarf, ask the toolchain for the default format.
3214
- if (!EmitCodeView && DWARFVersion == 0 &&
3219
+ if (!EmitCodeView && !EmitDwarf &&
3215
3220
DebugInfoKind != codegenoptions::NoDebugInfo) {
3216
3221
switch (TC.getDefaultDebugFormat ()) {
3217
3222
case codegenoptions::DIF_CodeView:
3218
3223
EmitCodeView = true ;
3219
3224
break ;
3220
3225
case codegenoptions::DIF_DWARF:
3221
- DWARFVersion = TC. GetDefaultDwarfVersion () ;
3226
+ EmitDwarf = true ;
3222
3227
break ;
3223
3228
}
3224
3229
}
3225
3230
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
+
3226
3241
// -gline-directives-only supported only for the DWARF debug info.
3227
3242
if (DWARFVersion == 0 && DebugInfoKind == codegenoptions::DebugDirectivesOnly)
3228
3243
DebugInfoKind = codegenoptions::NoDebugInfo;
0 commit comments