-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[flang][driver] Support -gdwarf-N option. #158314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-flang-driver Author: Abid Qadeer (abidh) ChangesThis 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. Fixes #112910. Full diff: https://github.com/llvm/llvm-project/pull/158314.diff 5 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 49e917a6a0786..7768f56fbd77e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4674,10 +4674,11 @@ def ggdb3 : Flag<["-"], "ggdb3">, Group<ggdbN_Group>;
def glldb : Flag<["-"], "glldb">, Group<gTune_Group>;
def gsce : Flag<["-"], "gsce">, Group<gTune_Group>;
def gdbx : Flag<["-"], "gdbx">, Group<gTune_Group>;
+
+let Visibility = [ClangOption, CLOption, DXCOption, FlangOption] in {
// Equivalent to our default dwarf version. Forces usual dwarf emission when
// CodeView is enabled.
def gdwarf : Flag<["-"], "gdwarf">, Group<g_Group>,
- Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Generate source-level debug information with the default dwarf version">;
def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 2">;
@@ -4687,6 +4688,7 @@ def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 4">;
def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 5">;
+}
def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
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=">;
def record_command_line : Separate<["-"], "record-command-line">,
HelpText<"The string to embed in the .LLVM.command.line section.">,
MarshallingInfoString<CodeGenOpts<"RecordCommandLine">>;
+def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
+ MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
} // let Visibility = [CC1Option, CC1AsOption, FC1Option]
@@ -7637,8 +7641,6 @@ def debug_info_macro : Flag<["-"], "debug-info-macro">,
def default_function_attr : Separate<["-"], "default-function-attr">,
HelpText<"Apply given attribute to all functions">,
MarshallingInfoStringVector<CodeGenOpts<"DefaultFunctionAttrs">>;
-def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
- MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">,
Values<"gdb,lldb,sce,dbx">,
NormalizedValuesScope<"llvm::DebuggerKind">, NormalizedValues<["GDB", "LLDB", "SCE", "DBX"]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 1535f4cebf436..2118c67dedc54 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -134,12 +134,17 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
if (Args.hasArg(options::OPT_gN_Group)) {
Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
DebugInfoKind = debugLevelToInfoKind(*gNArg);
- } else if (Args.hasArg(options::OPT_g_Flag)) {
+ } else if (Args.hasArg(options::OPT_g_Group)) {
DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
} else {
DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
}
addDebugInfoKind(CmdArgs, DebugInfoKind);
+ if (getDwarfNArg(Args)) {
+ const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
+ CmdArgs.push_back(
+ Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion)));
+ }
}
void Flang::addCodegenOptions(const ArgList &Args,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def b/flang/include/flang/Frontend/CodeGenOptions.def
index cdeea93c9aecb..22f778c5d3d38 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -46,6 +46,7 @@ CODEGENOPT(InterchangeLoops, 1, 0) ///< Enable loop interchange.
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
+CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
CODEGENOPT(Underscoring, 1, 1)
ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) ///< Name of the relocation model to use.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 6295a58b1bdad..c7dbfc46f432c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -157,6 +157,10 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0");
diags.Report(debugWarning) << arg->getValue();
}
+ // The default value of 2 here is to match clang.
+ opts.DwarfVersion =
+ getLastArgIntValue(args, clang::driver::options::OPT_dwarf_version_EQ,
+ /*Default=*/2, diags);
}
return true;
}
diff --git a/flang/test/Driver/flang-dwarf-version.f90 b/flang/test/Driver/flang-dwarf-version.f90
new file mode 100644
index 0000000000000..7319c47de04b7
--- /dev/null
+++ b/flang/test/Driver/flang-dwarf-version.f90
@@ -0,0 +1,27 @@
+// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF5 %s
+// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s
+// RUN: %flang -### -S %s -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s
+// RUN: %flang -### -S %s -gdwarf-4 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF4 %s
+// RUN: %flang -### -S %s -gdwarf-3 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN: %flang -### -S %s -gdwarf-2 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF2 %s
+
+// CHECK-WITH-G-DWARF5: -debug-info-kind=standalone
+// CHECK-WITH-G-DWARF5-SAME: -dwarf-version=5
+
+// CHECK-WITH-G1-DWARF5: -debug-info-kind=line-tables-only
+// CHECK-WITH-G1-DWARF5-SAME: -dwarf-version=5
+
+// CHECK-WITHOUT-G-DWARF5: -debug-info-kind=standalone
+// CHECK-WITHOUT-G-DWARF5: -dwarf-version=5
+
+// CHECK-DWARF4: -dwarf-version=4
+
+// CHECK-DWARF3: -dwarf-version=3
+
+// CHECK-DWARF2: -dwarf-version=2
|
@llvm/pr-subscribers-clang Author: Abid Qadeer (abidh) ChangesThis 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. Fixes #112910. Full diff: https://github.com/llvm/llvm-project/pull/158314.diff 5 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 49e917a6a0786..7768f56fbd77e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4674,10 +4674,11 @@ def ggdb3 : Flag<["-"], "ggdb3">, Group<ggdbN_Group>;
def glldb : Flag<["-"], "glldb">, Group<gTune_Group>;
def gsce : Flag<["-"], "gsce">, Group<gTune_Group>;
def gdbx : Flag<["-"], "gdbx">, Group<gTune_Group>;
+
+let Visibility = [ClangOption, CLOption, DXCOption, FlangOption] in {
// Equivalent to our default dwarf version. Forces usual dwarf emission when
// CodeView is enabled.
def gdwarf : Flag<["-"], "gdwarf">, Group<g_Group>,
- Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Generate source-level debug information with the default dwarf version">;
def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 2">;
@@ -4687,6 +4688,7 @@ def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 4">;
def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 5">;
+}
def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
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=">;
def record_command_line : Separate<["-"], "record-command-line">,
HelpText<"The string to embed in the .LLVM.command.line section.">,
MarshallingInfoString<CodeGenOpts<"RecordCommandLine">>;
+def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
+ MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
} // let Visibility = [CC1Option, CC1AsOption, FC1Option]
@@ -7637,8 +7641,6 @@ def debug_info_macro : Flag<["-"], "debug-info-macro">,
def default_function_attr : Separate<["-"], "default-function-attr">,
HelpText<"Apply given attribute to all functions">,
MarshallingInfoStringVector<CodeGenOpts<"DefaultFunctionAttrs">>;
-def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
- MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">,
Values<"gdb,lldb,sce,dbx">,
NormalizedValuesScope<"llvm::DebuggerKind">, NormalizedValues<["GDB", "LLDB", "SCE", "DBX"]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 1535f4cebf436..2118c67dedc54 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -134,12 +134,17 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
if (Args.hasArg(options::OPT_gN_Group)) {
Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
DebugInfoKind = debugLevelToInfoKind(*gNArg);
- } else if (Args.hasArg(options::OPT_g_Flag)) {
+ } else if (Args.hasArg(options::OPT_g_Group)) {
DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
} else {
DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
}
addDebugInfoKind(CmdArgs, DebugInfoKind);
+ if (getDwarfNArg(Args)) {
+ const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
+ CmdArgs.push_back(
+ Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion)));
+ }
}
void Flang::addCodegenOptions(const ArgList &Args,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def b/flang/include/flang/Frontend/CodeGenOptions.def
index cdeea93c9aecb..22f778c5d3d38 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -46,6 +46,7 @@ CODEGENOPT(InterchangeLoops, 1, 0) ///< Enable loop interchange.
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
+CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
CODEGENOPT(Underscoring, 1, 1)
ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) ///< Name of the relocation model to use.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 6295a58b1bdad..c7dbfc46f432c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -157,6 +157,10 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0");
diags.Report(debugWarning) << arg->getValue();
}
+ // The default value of 2 here is to match clang.
+ opts.DwarfVersion =
+ getLastArgIntValue(args, clang::driver::options::OPT_dwarf_version_EQ,
+ /*Default=*/2, diags);
}
return true;
}
diff --git a/flang/test/Driver/flang-dwarf-version.f90 b/flang/test/Driver/flang-dwarf-version.f90
new file mode 100644
index 0000000000000..7319c47de04b7
--- /dev/null
+++ b/flang/test/Driver/flang-dwarf-version.f90
@@ -0,0 +1,27 @@
+// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF5 %s
+// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s
+// RUN: %flang -### -S %s -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s
+// RUN: %flang -### -S %s -gdwarf-4 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF4 %s
+// RUN: %flang -### -S %s -gdwarf-3 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN: %flang -### -S %s -gdwarf-2 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF2 %s
+
+// CHECK-WITH-G-DWARF5: -debug-info-kind=standalone
+// CHECK-WITH-G-DWARF5-SAME: -dwarf-version=5
+
+// CHECK-WITH-G1-DWARF5: -debug-info-kind=line-tables-only
+// CHECK-WITH-G1-DWARF5-SAME: -dwarf-version=5
+
+// CHECK-WITHOUT-G-DWARF5: -debug-info-kind=standalone
+// CHECK-WITHOUT-G-DWARF5: -dwarf-version=5
+
+// CHECK-DWARF4: -dwarf-version=4
+
+// CHECK-DWARF3: -dwarf-version=3
+
+// CHECK-DWARF2: -dwarf-version=2
|
@llvm/pr-subscribers-clang-driver Author: Abid Qadeer (abidh) ChangesThis 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. Fixes #112910. Full diff: https://github.com/llvm/llvm-project/pull/158314.diff 5 Files Affected:
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 49e917a6a0786..7768f56fbd77e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4674,10 +4674,11 @@ def ggdb3 : Flag<["-"], "ggdb3">, Group<ggdbN_Group>;
def glldb : Flag<["-"], "glldb">, Group<gTune_Group>;
def gsce : Flag<["-"], "gsce">, Group<gTune_Group>;
def gdbx : Flag<["-"], "gdbx">, Group<gTune_Group>;
+
+let Visibility = [ClangOption, CLOption, DXCOption, FlangOption] in {
// Equivalent to our default dwarf version. Forces usual dwarf emission when
// CodeView is enabled.
def gdwarf : Flag<["-"], "gdwarf">, Group<g_Group>,
- Visibility<[ClangOption, CLOption, DXCOption]>,
HelpText<"Generate source-level debug information with the default dwarf version">;
def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 2">;
@@ -4687,6 +4688,7 @@ def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 4">;
def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 5">;
+}
def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
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=">;
def record_command_line : Separate<["-"], "record-command-line">,
HelpText<"The string to embed in the .LLVM.command.line section.">,
MarshallingInfoString<CodeGenOpts<"RecordCommandLine">>;
+def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
+ MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
} // let Visibility = [CC1Option, CC1AsOption, FC1Option]
@@ -7637,8 +7641,6 @@ def debug_info_macro : Flag<["-"], "debug-info-macro">,
def default_function_attr : Separate<["-"], "default-function-attr">,
HelpText<"Apply given attribute to all functions">,
MarshallingInfoStringVector<CodeGenOpts<"DefaultFunctionAttrs">>;
-def dwarf_version_EQ : Joined<["-"], "dwarf-version=">,
- MarshallingInfoInt<CodeGenOpts<"DwarfVersion">>;
def debugger_tuning_EQ : Joined<["-"], "debugger-tuning=">,
Values<"gdb,lldb,sce,dbx">,
NormalizedValuesScope<"llvm::DebuggerKind">, NormalizedValues<["GDB", "LLDB", "SCE", "DBX"]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 1535f4cebf436..2118c67dedc54 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -134,12 +134,17 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
if (Args.hasArg(options::OPT_gN_Group)) {
Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
DebugInfoKind = debugLevelToInfoKind(*gNArg);
- } else if (Args.hasArg(options::OPT_g_Flag)) {
+ } else if (Args.hasArg(options::OPT_g_Group)) {
DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
} else {
DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
}
addDebugInfoKind(CmdArgs, DebugInfoKind);
+ if (getDwarfNArg(Args)) {
+ const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
+ CmdArgs.push_back(
+ Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion)));
+ }
}
void Flang::addCodegenOptions(const ArgList &Args,
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def b/flang/include/flang/Frontend/CodeGenOptions.def
index cdeea93c9aecb..22f778c5d3d38 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -46,6 +46,7 @@ CODEGENOPT(InterchangeLoops, 1, 0) ///< Enable loop interchange.
CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
+CODEGENOPT(DwarfVersion, 3, 0) ///< Dwarf version
CODEGENOPT(Underscoring, 1, 1)
ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) ///< Name of the relocation model to use.
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 6295a58b1bdad..c7dbfc46f432c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -157,6 +157,10 @@ static bool parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
clang::DiagnosticsEngine::Warning, "Unsupported debug option: %0");
diags.Report(debugWarning) << arg->getValue();
}
+ // The default value of 2 here is to match clang.
+ opts.DwarfVersion =
+ getLastArgIntValue(args, clang::driver::options::OPT_dwarf_version_EQ,
+ /*Default=*/2, diags);
}
return true;
}
diff --git a/flang/test/Driver/flang-dwarf-version.f90 b/flang/test/Driver/flang-dwarf-version.f90
new file mode 100644
index 0000000000000..7319c47de04b7
--- /dev/null
+++ b/flang/test/Driver/flang-dwarf-version.f90
@@ -0,0 +1,27 @@
+// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF5 %s
+// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s
+// RUN: %flang -### -S %s -gdwarf-5 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s
+// RUN: %flang -### -S %s -gdwarf-4 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF4 %s
+// RUN: %flang -### -S %s -gdwarf-3 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN: %flang -### -S %s -gdwarf-2 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-DWARF2 %s
+
+// CHECK-WITH-G-DWARF5: -debug-info-kind=standalone
+// CHECK-WITH-G-DWARF5-SAME: -dwarf-version=5
+
+// CHECK-WITH-G1-DWARF5: -debug-info-kind=line-tables-only
+// CHECK-WITH-G1-DWARF5-SAME: -dwarf-version=5
+
+// CHECK-WITHOUT-G-DWARF5: -debug-info-kind=standalone
+// CHECK-WITHOUT-G-DWARF5: -dwarf-version=5
+
+// CHECK-DWARF4: -dwarf-version=4
+
+// CHECK-DWARF3: -dwarf-version=3
+
+// CHECK-DWARF2: -dwarf-version=2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit, otherwise LG
def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>, | ||
HelpText<"Generate source-level debug information with dwarf version 4">; | ||
def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group<g_Group>, | ||
HelpText<"Generate source-level debug information with dwarf version 5">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this doesn't change the non-flang visibility of these options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think I have fixed it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @abidh , Thank you for the change. LGTM except the default visibility change. However, merging this change alone would mean flang would be accepting this option without any indication that it is not handled. It would be nice if
- In Flang.cpp, you can throw a warning that it is not handled
- Move the codegen opts changes (CompilerInvocation and CodeGenOpt) to the lowering changes so they get tested when the lowering change is added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you expect to land the code that handles this option relatively soon? If so, adding a warning indicating that the option is accepted but not handled is unnecessary, but if not, @anchuraj's suggestion is reasonable.
// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \ | ||
// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s | ||
// RUN: %flang -### -S %s -gdwarf-5 2>&1 \ | ||
// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirming: in this case, do -debug-info-kind=standalone
and -dwarf-version=5
appear in different lines? Is that the only difference between this and CHECK-WITH-G-DWARF5
? My first thought was that they seem to be checking the same thing and the prefix could be renamed to avoid the redundancy. But I notice that one of them has -SAME
and the other does not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One line was missing -SAME. I have fixes that now. The difference is that CHECK-WITH-G-DWARF5
has -g -gdwarf-5
while CHECK-WITHOUT-G-DWARF5
does not extra -g
. It tests that just adding -gdwarf-5
enables -g
functionality.
Yes, I plan to add that functionality this week. |
Sounds great. Please skip my warning suggestion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. Just one suggestion
// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \ | ||
// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF5 %s | ||
// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \ | ||
// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s | ||
// RUN: %flang -### -S %s -gdwarf-5 2>&1 \ | ||
// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps both CHECK-WITH-G-DWARF5
and CHECK-WITHOUT-G-DWARF5
could be replaced with a single CHECK-DWARF5
. By swapping the tests, it becomes more obvious that in one case, -g
is provided, while in the other, it is not. Since the check prefix now has the same name, it is clear that the expected behavior is the same.
For instance:
// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \ | |
// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF5 %s | |
// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \ | |
// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s | |
// RUN: %flang -### -S %s -gdwarf-5 2>&1 \ | |
// RUN: | FileCheck --check-prefix=CHECK-WITHOUT-G-DWARF5 %s | |
// RUN: %flang -### -S %s -g -gdwarf-5 2>&1 \ | |
// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s | |
// RUN: %flang -### -S %s -gdwarf-5 2>&1 \ | |
// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s | |
// RUN: %flang -### -S %s -g1 -gdwarf-5 2>&1 \ | |
// RUN: | FileCheck --check-prefix=CHECK-WITH-G1-DWARF5 %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. That is a good suggestion. I have updated the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, Abid. LGTM.
This PR builds on the llvm#158314 and adds the lowering support for -gdwarf-N flag. The changes to pass the information to AddDebugInfo pass are mostly mechanical. The AddDebugInfo pass adds ModuleFlagsOp in the module. This gets translated to correct llvm metadata during mlir->llvmir translation. There is minor correction where the version is set to 0 in case no -debug-version flag is provided. Previously it was set to 2 in this case due to misreading of clang code.
This PR builds on the #158314 and adds the lowering support for `-gdwarf-N` flag. The changes to pass the information to `AddDebugInfo` pass are mostly mechanical. The `AddDebugInfo` pass adds `ModuleFlagsOp` in the module which gets translated to correct llvm metadata during mlir->llvmir translation. There is minor correction where the version is set to 0 in case no -debug-version flag is provided. Previously it was set to 2 in this case due to misreading of clang code.
This PR builds on the llvm/llvm-project#158314 and adds the lowering support for `-gdwarf-N` flag. The changes to pass the information to `AddDebugInfo` pass are mostly mechanical. The `AddDebugInfo` pass adds `ModuleFlagsOp` in the module which gets translated to correct llvm metadata during mlir->llvmir translation. There is minor correction where the version is set to 0 in case no -debug-version flag is provided. Previously it was set to 2 in this case due to misreading of clang code.
I see that one of the test added in this is failing on https://lab.llvm.org/buildbot/#/builders/201/builds/6288. I will investigate it. |
|
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.
Fixes #112910.