Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4677,8 +4677,10 @@ def gdbx : Flag<["-"], "gdbx">, Group<gTune_Group>;
// 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]>,
Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
HelpText<"Generate source-level debug information with the default dwarf version">;

let Visibility = [ClangOption, FlangOption] in {
def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>,
HelpText<"Generate source-level debug information with dwarf version 2">;
def gdwarf_3 : Flag<["-"], "gdwarf-3">, Group<g_Group>,
Expand All @@ -4687,6 +4689,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">;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

}
def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
HelpText<"Enables DWARF64 format for ELF binaries, if debug information emission is enabled.">,
Expand Down Expand Up @@ -7626,6 +7629,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]

Expand All @@ -7637,8 +7642,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"]>,
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions flang/include/flang/Frontend/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions flang/test/Driver/flang-dwarf-version.f90
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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:

Suggested change
// 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

Copy link
Contributor Author

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.

// 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-SAME: -dwarf-version=5

// CHECK-DWARF4: -dwarf-version=4

// CHECK-DWARF3: -dwarf-version=3

// CHECK-DWARF2: -dwarf-version=2
Loading