Skip to content

Commit 42df544

Browse files
[Clang][DebugInfo] Clang generates an extra spurious unnamed 'dbg.declare'.
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 8d80a45 commit 42df544

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
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() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone %s -o - | FileCheck %s
2+
3+
struct Tuple {
4+
int Fld_1;
5+
int Fld_2;
6+
};
7+
__attribute__((optnone)) Tuple get() { return {10, 20}; }
8+
9+
// CHECK-LABEL: define dso_local noundef i32 @main
10+
// CHECK: %retval = alloca i32, align 4
11+
// CHECK-NEXT: [[T0:%.*]] = alloca %struct.Tuple, align 4
12+
// CHECK: call void @llvm.dbg.declare(metadata ptr [[T0]], metadata {{.*}}, metadata !DIExpression())
13+
// CHECK: call void @llvm.dbg.declare(metadata ptr [[T0]], metadata {{.*}}, metadata !DIExpression(DW_OP_plus_uconst, {{[0-9]+}}))
14+
// CHECK-NOT: call void @llvm.dbg.declare(metadata ptr [[T0]], metadata {{.*}}, metadata !DIExpression())
15+
//
16+
int main() {
17+
auto [Var_1, Var_2] = get();
18+
19+
return Var_1 + Var_2;
20+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression())
44
// 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())
65
// CHECK: call void @llvm.dbg.declare(metadata ptr %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref))
76
// 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())
97
struct A {
108
int x;
119
int y;

0 commit comments

Comments
 (0)