Skip to content

Commit 2399c77

Browse files
[Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare' (#69681)
Do not emit call to llvm.dbg.declare when the variable declaration is a DecompositionDecl as its instance class is always unnamed. The emitted debug declare looks like: call void @llvm.dbg.declare(metadata ..., metadata !xx, metadata ...) !xx = !DILocalVariable(scope: !..., file: !..., line: ..., type: !...)
1 parent c912f88 commit 2399c77

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4881,11 +4881,15 @@ CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, llvm::Value *Storage,
48814881
const bool UsePointerValue) {
48824882
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
48834883

4884-
if (auto *DD = dyn_cast<DecompositionDecl>(VD))
4884+
if (auto *DD = dyn_cast<DecompositionDecl>(VD)) {
48854885
for (auto *B : DD->bindings()) {
48864886
EmitDeclare(B, Storage, std::nullopt, Builder,
48874887
VD->getType()->isReferenceType());
48884888
}
4889+
// Don't emit an llvm.dbg.declare for the composite storage as it doesn't
4890+
// correspond to a user variable.
4891+
return nullptr;
4892+
}
48894893

48904894
return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
48914895
}

clang/test/CodeGenCXX/debug-info-structured-binding-bitfield.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ struct S11 {
189189
// CHECK-LABEL: define dso_local void @_Z4fS11v
190190
// CHECK: alloca %struct.S11, align 4
191191
// CHECK-NEXT: [[TMP0:%.*]] = alloca %struct.S11, align 4
192-
// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
193192
// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
194193
//
195194
void fS11() {
@@ -206,7 +205,6 @@ struct S12 {
206205
// CHECK: alloca %struct.S12, align 4
207206
// CHECK-NEXT: [[TMP0:%.*]] = alloca %struct.S12, align 4
208207
// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata [[S12_A:![0-9]+]], metadata !DIExpression())
209-
// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
210208
// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
211209
//
212210
void fS12() {
@@ -222,7 +220,6 @@ struct __attribute__((packed)) S13 {
222220
// CHECK-LABEL: define dso_local void @_Z4fS13v
223221
// CHECK: alloca %struct.S13, align 1
224222
// CHECK-NEXT: [[TMP0:%.*]] = alloca %struct.S13, align 1
225-
// CHECK: call void @llvm.dbg.declare(metadata ptr [[TMP0]], metadata {{.*}}, metadata !DIExpression())
226223
// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[TMP0]]
227224
//
228225
void fS13() {

clang/test/CodeGenCXX/debug-info-structured-binding.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple %itanium_abi_triple %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple %itanium_abi_triple %s -o - | FileCheck %s --implicit-check-not="call void @llvm.dbg.declare"
2+
3+
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[a-z]+}}, metadata ![[VAR_0:[0-9]+]], metadata !DIExpression())
4+
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata ![[VAR_1:[0-9]+]], metadata !DIExpression())
5+
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata ![[VAR_2:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 4))
6+
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata ![[VAR_3:[0-9]+]], metadata !DIExpression(DW_OP_deref))
7+
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata ![[VAR_4:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 4))
8+
// CHECK: ![[VAR_0]] = !DILocalVariable(name: "a"
9+
// CHECK: ![[VAR_1]] = !DILocalVariable(name: "x1"
10+
// CHECK: ![[VAR_2]] = !DILocalVariable(name: "y1"
11+
// CHECK: ![[VAR_3]] = !DILocalVariable(name: "x2"
12+
// CHECK: ![[VAR_4]] = !DILocalVariable(name: "y2"
213

3-
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression())
4-
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}))
5-
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression())
6-
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref))
7-
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}))
8-
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression())
914
struct A {
1015
int x;
1116
int y;

0 commit comments

Comments
 (0)