Skip to content

Commit 520cecd

Browse files
committed
[flang][driver] Support -gdwarf-N option.
This PR adds the support for -gdwarf-N option where allows user to choose the version of the dwarf. Currently N can be 2, 3, 4, or 5. This is only the driver part of the change. Later PRs will propogate it to the IR.
1 parent 6bbf0c3 commit 520cecd

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,10 +4674,11 @@ def ggdb3 : Flag<["-"], "ggdb3">, Group<ggdbN_Group>;
46744674
def glldb : Flag<["-"], "glldb">, Group<gTune_Group>;
46754675
def gsce : Flag<["-"], "gsce">, Group<gTune_Group>;
46764676
def gdbx : Flag<["-"], "gdbx">, Group<gTune_Group>;
4677+
4678+
let Visibility = [ClangOption, CLOption, DXCOption, FlangOption] in {
46774679
// Equivalent to our default dwarf version. Forces usual dwarf emission when
46784680
// CodeView is enabled.
46794681
def gdwarf : Flag<["-"], "gdwarf">, Group<g_Group>,
4680-
Visibility<[ClangOption, CLOption, DXCOption]>,
46814682
HelpText<"Generate source-level debug information with the default dwarf version">;
46824683
def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>,
46834684
HelpText<"Generate source-level debug information with dwarf version 2">;
@@ -4687,6 +4688,7 @@ def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>,
46874688
HelpText<"Generate source-level debug information with dwarf version 4">;
46884689
def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group<g_Group>,
46894690
HelpText<"Generate source-level debug information with dwarf version 5">;
4691+
}
46904692
def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>,
46914693
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
46924694
HelpText<"Enables DWARF64 format for ELF binaries, if debug information emission is enabled.">,
@@ -7626,6 +7628,8 @@ def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
76267628
def record_command_line : Separate<["-"], "record-command-line">,
76277629
HelpText<"The string to embed in the .LLVM.command.line section.">,
76287630
MarshallingInfoString<CodeGenOpts<"RecordCommandLine">>;
7631+
def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
7632+
MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
76297633

76307634
} // let Visibility = [CC1Option, CC1AsOption, FC1Option]
76317635

@@ -7637,8 +7641,6 @@ def debug_info_macro : Flag<["-"], "debug-info-macro">,
76377641
def default_function_attr : Separate<["-"], "default-function-attr">,
76387642
HelpText<"Apply given attribute to all functions">,
76397643
MarshallingInfoStringVector<CodeGenOpts<"DefaultFunctionAttrs">>;
7640-
def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
7641-
MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
76427644
def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">,
76437645
Values<"gdb,lldb,sce,dbx">,
76447646
NormalizedValuesScope<"llvm::DebuggerKind">, NormalizedValues<["GDB", "LLDB", "SCE", "DBX"]>,

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,17 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
134134
if (Args.hasArg(options::OPT_gN_Group)) {
135135
Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
136136
DebugInfoKind = debugLevelToInfoKind(*gNArg);
137-
} else if (Args.hasArg(options::OPT_g_Flag)) {
137+
} else if (Args.hasArg(options::OPT_g_Group)) {
138138
DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
139139
} else {
140140
DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
141141
}
142142
addDebugInfoKind(CmdArgs, DebugInfoKind);
143+
if (getDwarfNArg(Args)) {
144+
const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
145+
CmdArgs.push_back(
146+
Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion)));
147+
}
143148
}
144149

145150
void Flang::addCodegenOptions(const ArgList &Args,

flang/include/flang/Frontend/CodeGenOptions.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ CODEGENOPT(InterchangeLoops, 1, 0) ///< Enable loop interchange.
4646
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
4747
CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
4848
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
49+
CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
4950

5051
CODEGENOPT(Underscoring, 1, 1)
5152
ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) ///< Name of the relocation model to use.

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
157157
clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0");
158158
diags.Report(debugWarning) << arg->getValue();
159159
}
160+
// The default value of 2 here is to match clang.
161+
opts.DwarfVersion =
162+
getLastArgIntValue(args, clang::driver::options::OPT_dwarf_version_EQ,
163+
/*Default=*/2, diags);
160164
}
161165
return true;
162166
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \
2+
// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF5 %s
3+
// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \
4+
// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s
5+
// RUN: %flang -### -S %s -gdwarf-5 2>&1 \
6+
// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s
7+
// RUN: %flang -### -S %s -gdwarf-4 2>&1 \
8+
// RUN: | FileCheck --check-prefix=CHECK-DWARF4 %s
9+
// RUN: %flang -### -S %s -gdwarf-3 2>&1 \
10+
// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
11+
// RUN: %flang -### -S %s -gdwarf-2 2>&1 \
12+
// RUN: | FileCheck --check-prefix=CHECK-DWARF2 %s
13+
14+
// CHECK-WITH-G-DWARF5: -debug-info-kind=standalone
15+
// CHECK-WITH-G-DWARF5-SAME: -dwarf-version=5
16+
17+
// CHECK-WITH-G1-DWARF5: -debug-info-kind=line-tables-only
18+
// CHECK-WITH-G1-DWARF5-SAME: -dwarf-version=5
19+
20+
// CHECK-WITHOUT-G-DWARF5: -debug-info-kind=standalone
21+
// CHECK-WITHOUT-G-DWARF5: -dwarf-version=5
22+
23+
// CHECK-DWARF4: -dwarf-version=4
24+
25+
// CHECK-DWARF3: -dwarf-version=3
26+
27+
// CHECK-DWARF2: -dwarf-version=2

0 commit comments

Comments
 (0)