Skip to content

Commit 2ee5601

Browse files
committed
fixup! add clang driver option
1 parent 413acc0 commit 2ee5601

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

clang/include/clang/Basic/DebugOptions.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ DEBUGOPT(DebugNameTable, 2, 0, Compatible)
125125
/// Whether to use DWARF base address specifiers in .debug_ranges.
126126
DEBUGOPT(DebugRangesBaseAddress, 1, 0, Compatible)
127127

128+
/// Whether to add linkage names to constructor/destructor declarations.
129+
DEBUGOPT(DebugStructorDeclLinkageNames, 1, 0, Benign)
130+
128131
/// Whether to embed source in DWARF debug line section.
129-
DEBUGOPT(EmbedSource, 1, 0, Compatible)
132+
DEBUGOPT(EmbedSource, 1, 1, Compatible)
130133

131134
#undef DEBUGOPT
132135
#undef ENUM_DEBUGOPT

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,6 +4767,15 @@ def gembed_source : Flag<["-"], "gembed-source">, Group<g_flags_Group>,
47674767
def gno_embed_source : Flag<["-"], "gno-embed-source">, Group<g_flags_Group>,
47684768
Flags<[NoXarchOption]>,
47694769
HelpText<"Restore the default behavior of not embedding source text in DWARF debug sections">;
4770+
defm structor_decl_linkage_names
4771+
: BoolGOption<"structor-decl-linkage-names",
4772+
CodeGenOpts<"DebugStructorDeclLinkageNames">, DefaultTrue,
4773+
NegFlag<SetFalse>,
4774+
PosFlag<SetTrue, [], [],
4775+
"Attach linkage names to C++ constructor/destructor "
4776+
"declarations in DWARF."
4777+
"Implies -g.">,
4778+
BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
47704779
defm key_instructions : BoolGOption<"key-instructions",
47714780
CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
47724781
NegFlag<SetFalse>, PosFlag<SetTrue, [], [],

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,9 +2181,12 @@ llvm::StringRef
21812181
CGDebugInfo::GetMethodLinkageName(const CXXMethodDecl *Method) const {
21822182
assert(Method);
21832183

2184-
bool IsCtorOrDtor =
2184+
const bool IsCtorOrDtor =
21852185
isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
21862186

2187+
if (IsCtorOrDtor && !CGM.getCodeGenOpts().DebugStructorDeclLinkageNames)
2188+
return {};
2189+
21872190
// In some ABIs (particularly Itanium) a single ctor/dtor
21882191
// corresponds to multiple functions. Attach a "unified"
21892192
// linkage name for those (which is the convention GCC uses).

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,10 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
45954595
options::OPT_gno_key_instructions, false))
45964596
CmdArgs.push_back("-gkey-instructions");
45974597

4598+
if (!Args.hasFlag(options::OPT_gstructor_decl_linkage_names,
4599+
options::OPT_gno_structor_decl_linkage_names, true))
4600+
CmdArgs.push_back("-gno-structor-decl-linkage-names");
4601+
45984602
if (EmitCodeView) {
45994603
CmdArgs.push_back("-gcodeview");
46004604

clang/test/CodeGenCXX/debug-info-structor-linkage-names.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
// Tests that we emit unified constructor/destructor linkage names
22
// for ABIs that support it.
33

4-
// RUN: %clang_cc1 -triple aarch64-apple-macosx -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM
5-
// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s --check-prefixes=CHECK,MSABI
4+
// Check that -gstructor-decl-linkage-names is the default.
5+
// RUN: %clang_cc1 -triple aarch64-apple-macosx -emit-llvm -debug-info-kind=standalone \
6+
// RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM
7+
//
8+
// Check with -gstructor-decl-linkage-names.
9+
// RUN: %clang_cc1 -triple aarch64-apple-macosx -emit-llvm -debug-info-kind=standalone \
10+
// RUN: -gstructor-decl-linkage-names %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM
11+
//
12+
// Check with -gno-structor-decl-linkage-names.
13+
// RUN: %clang_cc1 -triple aarch64-apple-macosx -emit-llvm -debug-info-kind=standalone \
14+
// RUN: -gno-structor-decl-linkage-names %s -o - | FileCheck %s --check-prefixes=CHECK,DISABLE
15+
//
16+
// Check ABI without structor variants.
17+
// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -debug-info-kind=standalone \
18+
// RUN: -gstructor-decl-linkage-names %s -o - | FileCheck %s --check-prefixes=CHECK,MSABI
619

720
struct Base {
821
Base(int x);
@@ -16,11 +29,13 @@ Base::~Base() {}
1629

1730
// CHECK: ![[BASE_CTOR_DECL:[0-9]+]] = !DISubprogram(name: "Base"
1831
// MSABI-NOT: linkageName:
32+
// DISABLE-NOT: linkageName:
1933
// ITANIUM-SAME: linkageName: "_ZN4BaseC4Ei"
2034
// CHECK-SAME: spFlags: 0
2135

2236
// CHECK: ![[BASE_DTOR_DECL:[0-9]+]] = !DISubprogram(name: "~Base"
2337
// MSABI-NOT: linkageName:
38+
// DISABLE-NOT: linkageName:
2439
// ITANIUM-SAME: linkageName: "_ZN4BaseD4Ev"
2540
// CHECK-SAME: spFlags: 0
2641

@@ -61,6 +76,7 @@ struct Derived : public Base {
6176

6277
// CHECK: [[BASE_INHERIT_CTOR_DECL]] = !DISubprogram(name: "Base"
6378
// MSABI-NOT: linkageName:
79+
// DISABLE-NOT: linkageName:
6480
// ITANIUM-SAME: linkageName: "_ZN7DerivedCI44BaseEi"
6581
// CHECK-SAME spFlags: 0
6682

0 commit comments

Comments
 (0)