@@ -981,6 +981,14 @@ static unsigned DwarfVersionNum(StringRef ArgValue) {
981
981
.Default (0 );
982
982
}
983
983
984
+ // Find a DWARF format version option.
985
+ // This function is a complementary for DwarfVersionNum().
986
+ static const Arg *getDwarfNArg (const ArgList &Args) {
987
+ return Args.getLastArg (options::OPT_gdwarf_2, options::OPT_gdwarf_3,
988
+ options::OPT_gdwarf_4, options::OPT_gdwarf_5,
989
+ options::OPT_gdwarf);
990
+ }
991
+
984
992
static void RenderDebugEnablingArgs (const ArgList &Args, ArgStringList &CmdArgs,
985
993
codegenoptions::DebugInfoKind DebugInfoKind,
986
994
unsigned DwarfVersion,
@@ -3848,9 +3856,7 @@ static void renderDebugOptions(const ToolChain &TC, const Driver &D,
3848
3856
}
3849
3857
3850
3858
// If a -gdwarf argument appeared, remember it.
3851
- const Arg *GDwarfN = Args.getLastArg (
3852
- options::OPT_gdwarf_2, options::OPT_gdwarf_3, options::OPT_gdwarf_4,
3853
- options::OPT_gdwarf_5, options::OPT_gdwarf);
3859
+ const Arg *GDwarfN = getDwarfNArg (Args);
3854
3860
bool EmitDwarf = false ;
3855
3861
if (GDwarfN) {
3856
3862
if (checkDebugInfoOption (GDwarfN, Args, D, TC))
@@ -7168,18 +7174,14 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
7168
7174
// Forward -g and handle debug info related flags, assuming we are dealing
7169
7175
// with an actual assembly file.
7170
7176
bool WantDebug = false ;
7171
- unsigned DwarfVersion = 0 ;
7172
7177
Args.ClaimAllArgs (options::OPT_g_Group);
7173
- if (Arg *A = Args.getLastArg (options::OPT_g_Group)) {
7178
+ if (Arg *A = Args.getLastArg (options::OPT_g_Group))
7174
7179
WantDebug = !A->getOption ().matches (options::OPT_g0) &&
7175
7180
!A->getOption ().matches (options::OPT_ggdb0);
7176
- if (WantDebug)
7177
- DwarfVersion = DwarfVersionNum (A->getSpelling ());
7178
- }
7179
7181
7180
- unsigned DefaultDwarfVersion = ParseDebugDefaultVersion (getToolChain (), Args);
7181
- if (DwarfVersion == 0 )
7182
- DwarfVersion = DefaultDwarfVersion ;
7182
+ unsigned DwarfVersion = ParseDebugDefaultVersion (getToolChain (), Args);
7183
+ if (const Arg *GDwarfN = getDwarfNArg (Args) )
7184
+ DwarfVersion = DwarfVersionNum (GDwarfN-> getSpelling ()) ;
7183
7185
7184
7186
if (DwarfVersion == 0 )
7185
7187
DwarfVersion = getToolChain ().GetDefaultDwarfVersion ();
0 commit comments