[clang] 843f2db - [Driver] Don't make -gsplit-dwarf imply -g2
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 8 13:14:40 PST 2020
Author: Fangrui Song
Date: 2020-12-08T13:14:34-08:00
New Revision: 843f2dbf003f2a51d0d4ab8cf40647c99ded2e93
URL: https://github.com/llvm/llvm-project/commit/843f2dbf003f2a51d0d4ab8cf40647c99ded2e93
DIFF: https://github.com/llvm/llvm-project/commit/843f2dbf003f2a51d0d4ab8cf40647c99ded2e93.diff
LOG: [Driver] Don't make -gsplit-dwarf imply -g2
RFC: http://lists.llvm.org/pipermail/cfe-dev/2020-May/065430.html
Agreement from GCC: https://sourceware.org/pipermail/gcc-patches/2020-May/545688.html
g_flags_Group options generally don't affect the amount of debugging
information. -gsplit-dwarf is an exception. Its order dependency with
other gN_Group options make it inconvenient in a build system:
* -g0 -gsplit-dwarf -> level 2
-gsplit-dwarf "upgrades" the amount of debugging information despite
the previous intention (-g0) to drop debugging information
* -g1 -gsplit-dwarf -> level 2
-gsplit-dwarf "upgrades" the amount of debugging information.
* If we have a higher-level -gN, -gN -gsplit-dwarf will supposedly decrease the
amount of debugging information. This happens with GCC -g3.
The non-orthogonality has confused many users. GCC 11 will change the semantics
(-gsplit-dwarf no longer implies -g2) despite the backwards compatibility break.
This patch matches its behavior.
New semantics:
* If there is a g_Group, allow split DWARF if useful
(none of: -g0, -gline-directives-only, -g1 -fno-split-dwarf-inlining)
* Otherwise, no-op.
To restore the original behavior, replace -gsplit-dwarf with -gsplit-dwarf -g.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D80391
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/split-debug.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d90d059e0659..7d68cdb99b48 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -117,6 +117,7 @@ Modified Compiler Flags
- Now that `this` pointers are tagged with `nonnull` and `dereferenceable(N)`,
`-fno-delete-null-pointer-checks` has gained the power to remove the
`nonnull` attribute on `this` for configurations that need it to be nullable.
+- ``-gsplit-dwarf`` no longer implies ``-g2``.
New Pragmas in Clang
--------------------
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index baf7d5c58e4a..f3a6b12609e2 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3750,20 +3750,15 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
options::OPT_fno_split_dwarf_inlining, false);
- Args.ClaimAllArgs(options::OPT_g_Group);
-
- Arg* SplitDWARFArg;
- DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
-
- if (DwarfFission != DwarfFissionKind::None &&
- !checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) {
- DwarfFission = DwarfFissionKind::None;
- SplitDWARFInlining = false;
- }
+ if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
+ Arg *SplitDWARFArg;
+ DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
+ if (DwarfFission != DwarfFissionKind::None &&
+ !checkDebugInfoOption(SplitDWARFArg, Args, D, TC)) {
+ DwarfFission = DwarfFissionKind::None;
+ SplitDWARFInlining = false;
+ }
- if (const Arg *A =
- Args.getLastArg(options::OPT_g_Group, options::OPT_gsplit_dwarf,
- options::OPT_gsplit_dwarf_EQ)) {
DebugInfoKind = codegenoptions::LimitedDebugInfo;
// If the last option explicitly specified a debug-info level, use it.
@@ -4896,7 +4891,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (D.IsCLMode())
AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
- DwarfFissionKind DwarfFission;
+ DwarfFissionKind DwarfFission = DwarfFissionKind::None;
RenderDebugOptions(TC, D, RawTriple, Args, EmitCodeView, CmdArgs,
DebugInfoKind, DwarfFission);
diff --git a/clang/test/Driver/split-debug.c b/clang/test/Driver/split-debug.c
index 4b644c8d60ae..bd9ec32e0010 100644
--- a/clang/test/Driver/split-debug.c
+++ b/clang/test/Driver/split-debug.c
@@ -20,8 +20,8 @@
// RUN: %clang -### -c -target x86_64-apple-darwin -gsplit-dwarf -g %s 2>&1 | FileCheck %s --check-prefix=NOSPLIT
// NOSPLIT-NOT: "-split-dwarf
-/// -gsplit-dwarf currently enables debug fission even without -g.
-// RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=SPLIT
+/// -gsplit-dwarf is a no-op if no -g is specified.
+// RUN: %clang -### -c -target x86_64 -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefix=G0
/// Test -gsplit-dwarf=single.
// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g %s 2>&1 | FileCheck %s --check-prefix=SINGLE
@@ -59,8 +59,8 @@
/// Interaction with -g0.
// RUN: %clang -### -c -target x86_64 -gsplit-dwarf -g0 -### %s 2>&1 | FileCheck %s --check-prefix=G0
// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g0 %s 2>&1 | FileCheck %s --check-prefix=G0
-// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
-// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf=single %s 2>&1 | FileCheck %s --check-prefix=SINGLE
+// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf %s 2>&1 | FileCheck %s --check-prefixes=G0
+// RUN: %clang -### -c -target x86_64 -g0 -gsplit-dwarf=single %s 2>&1 | FileCheck %s --check-prefix=G0
// RUN: %clang -### -c -target x86_64 -gsplit-dwarf=single -g0 -fsplit-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=G0
// G0-NOT: "-debug-info-kind=
@@ -69,7 +69,7 @@
/// Interaction with -g1 (-gmlt).
// RUN: %clang -### -S -target x86_64 -gsplit-dwarf -g1 %s 2>&1 | FileCheck %s --check-prefix=G1_WITH_SPLIT
// RUN: %clang -### -S -target x86_64 -gsplit-dwarf -g1 -fno-split-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=G1_WITH_SPLIT
-// RUN: %clang -### -S -target x86_64 -gmlt -gsplit-dwarf -fno-split-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=SPLIT
+// RUN: %clang -### -S -target x86_64 -gmlt -gsplit-dwarf -fno-split-dwarf-inlining %s 2>&1 | FileCheck %s --check-prefix=G1_WITH_SPLIT
// G1_WITH_SPLIT: "-debug-info-kind=line-tables-only"
// G1_WITH_SPLIT: "-split-dwarf-file"
More information about the cfe-commits
mailing list