[clang] [clang] Remove -g[no-]-* bool flags from g_Group (PR #162750)
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 10 15:02:03 PDT 2025
https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/162750
>From 853d60eb21eb7a56494925021fb608e41b812a61 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Thu, 9 Oct 2025 22:52:45 +0000
Subject: [PATCH 1/3] [clang] Remove -g[no-]-* bool flags from g_Group
There are four uses of BoolGOption, and all of them are essentially debug
info feature flags, which I believe should not the enablement or
disablement of all debug info emission. `OPT_g_group` is used to control
the debug info level here:
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/Clang.cpp#L4387
This doesn't cause any test failures, and seems like the right behavior
for all four flags:
* -g[no-]flag-base
* -g[no-]inline-line-tables
* -g[no-]key-instructions
* -g[no-]structor-decl-linkage-names
None of these, even in the positive form, should enable debug info
emission.
Fixes #162747
---
clang/include/clang/Driver/Options.td | 9 +++++----
clang/test/DebugInfo/KeyInstructions/flag.cpp | 3 +++
clang/test/Driver/debug-options.c | 6 +++---
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 9bfa1dd52effe..ced6f873516ba 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -545,15 +545,16 @@ multiclass BoolFOption<string flag_base, KeyPathAndMacro kpm,
Group<f_Group>;
}
-// Creates a BoolOption where both of the flags are prefixed with "g" and have
-// the Group<g_Group>.
+// Creates a BoolOption where both of the flags are prefixed with "g".
+// Does *not* map to g_Group, because that is reserved for flags that are
+// intended to enable (or disable) debug info, which is not appropriate for a
+// negative boolean flag (-gno-${feature}).
// Used for -cc1 frontend options. Driver-only options do not map to
// CompilerInvocation.
multiclass BoolGOption<string flag_base, KeyPathAndMacro kpm,
Default default, FlagDef flag1, FlagDef flag2,
BothFlags both = BothFlags<[]>> {
- defm NAME : BoolOption<"g", flag_base, kpm, default, flag1, flag2, both>,
- Group<g_Group>;
+ defm NAME : BoolOption<"g", flag_base, kpm, default, flag1, flag2, both>;
}
multiclass BoolMOption<string flag_base, KeyPathAndMacro kpm,
diff --git a/clang/test/DebugInfo/KeyInstructions/flag.cpp b/clang/test/DebugInfo/KeyInstructions/flag.cpp
index a5cd8558eae52..12802c1ccb823 100644
--- a/clang/test/DebugInfo/KeyInstructions/flag.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/flag.cpp
@@ -1,5 +1,6 @@
// RUN: %clang -### -target x86_64 -c -gdwarf -gkey-instructions %s 2>&1 | FileCheck %s --check-prefixes=KEY-INSTRUCTIONS
// RUN: %clang -### -target x86_64 -c -gdwarf -gno-key-instructions %s 2>&1 | FileCheck %s --check-prefixes=NO-KEY-INSTRUCTIONS
+// RUN: %clang -### -target x86_64 -c -gno-key-instructions %s 2>&1 | FileCheck %s --check-prefixes=NO-DEBUG
//// Help.
// RUN %clang --help | FileCheck %s --check-prefix=HELP
@@ -7,6 +8,8 @@
// KEY-INSTRUCTIONS: "-gkey-instructions"
// NO-KEY-INSTRUCTIONS-NOT: key-instructions
+// NO-DEBUG-NOT: debug-info-kind
+// NO-DEBUG-NOT: dwarf
//// Help hidden: flag should not be visible.
// RUN: %clang --help | FileCheck %s --check-prefix=HELP
diff --git a/clang/test/Driver/debug-options.c b/clang/test/Driver/debug-options.c
index 73f2f402efa97..45ac450ac8faa 100644
--- a/clang/test/Driver/debug-options.c
+++ b/clang/test/Driver/debug-options.c
@@ -268,11 +268,11 @@
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
// RUN: %clang -### -c -fdebug-ranges-base-address -fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
//
-// RUN: %clang -### -c -gomit-unreferenced-methods -fno-standalone-debug %s 2>&1 | FileCheck -check-prefix=INCTYPES %s
+// RUN: %clang -### -c -g -gomit-unreferenced-methods -fno-standalone-debug %s 2>&1 | FileCheck -check-prefix=INCTYPES %s
// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
-// RUN: %clang -### -c -gomit-unreferenced-methods -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 \
+// RUN: %clang -### -c -g -gomit-unreferenced-methods -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 \
// RUN: | FileCheck -check-prefix=NOINCTYPES %s
-// RUN: %clang -### -c -gomit-unreferenced-methods -fstandalone-debug %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
+// RUN: %clang -### -c -g -gomit-unreferenced-methods -fstandalone-debug %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
//
// RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
// RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
>From ecebd1ca75dbb6c69290e0b56ee82f6fbb870086 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Fri, 10 Oct 2025 21:57:36 +0000
Subject: [PATCH 2/3] Remove "implies -g" from the doc text
---
clang/include/clang/Driver/Options.td | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ced6f873516ba..054fd30b01ded 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4825,8 +4825,7 @@ defm structor_decl_linkage_names
NegFlag<SetFalse>,
PosFlag<SetTrue, [], [],
"Attach linkage names to C++ constructor/destructor "
- "declarations in DWARF."
- "Implies -g.">,
+ "declarations in DWARF.">,
BothFlags<[], [ClangOption, CLOption, CC1Option]>>,
DocBrief<[{On some ABIs (e.g., Itanium), constructors and destructors may have multiple variants. Historically, when generating DWARF, Clang did not attach ``DW_AT_linkage_name`` to structor DIEs because there were multiple possible manglings (depending on the structor variant) that could be used. With ``-gstructor-decl-linkage-names``, for ABIs with structor variants, we attach a "unified" mangled name to structor declarations DIEs which debuggers can use to look up all the definitions for a structor declaration. E.g., a "unified" mangled name ``_ZN3FooC4Ev`` may have multiple definitions associated with it such as ``_ZN3FooC1Ev`` and ``_ZN3FooC2Ev``.
@@ -4835,7 +4834,7 @@ defm key_instructions : BoolGOption<"key-instructions",
CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
NegFlag<SetFalse>, PosFlag<SetTrue, [], [],
"Enable Key Instructions, which reduces the jumpiness of debug stepping in optimized C/C++ code"
- " in some debuggers. DWARF only. Implies -g.">,
+ " in some debuggers. DWARF only.">,
BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">;
def help : Flag<["-", "--"], "help">,
>From 5c2e500616ac1e54d86fe457db821f662ed64a4c Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Fri, 10 Oct 2025 22:01:47 +0000
Subject: [PATCH 3/3] fix flag.cpp test
---
clang/test/DebugInfo/KeyInstructions/flag.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/DebugInfo/KeyInstructions/flag.cpp b/clang/test/DebugInfo/KeyInstructions/flag.cpp
index 12802c1ccb823..6aeeed664135e 100644
--- a/clang/test/DebugInfo/KeyInstructions/flag.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/flag.cpp
@@ -4,7 +4,7 @@
//// Help.
// RUN %clang --help | FileCheck %s --check-prefix=HELP
-// HELP: -gkey-instructions Enable Key Instructions, which reduces the jumpiness of debug stepping in optimized C/C++ code in some debuggers. DWARF only. Implies -g.
+// HELP: -gkey-instructions Enable Key Instructions, which reduces the jumpiness of debug stepping in optimized C/C++ code in some debuggers. DWARF only.
// KEY-INSTRUCTIONS: "-gkey-instructions"
// NO-KEY-INSTRUCTIONS-NOT: key-instructions
More information about the cfe-commits
mailing list