Skip to content

Commit 4792971

Browse files
Michael137zeroomega
authored andcommitted
[clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available
1 parent d6e71a2 commit 4792971

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5518,11 +5518,17 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
55185518
}
55195519
AppendAddressSpaceXDeref(AddressSpace, Expr);
55205520

5521+
llvm::DIExpression *E = nullptr;
5522+
if (Expr.empty()) {
5523+
if (auto const *InitVal = evaluateConstantInitializer(D))
5524+
E = createConstantValueExpression(D, *InitVal);
5525+
} else
5526+
E = DBuilder.createExpression(Expr);
5527+
55215528
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
55225529
GVE = DBuilder.createGlobalVariableExpression(
55235530
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
5524-
Var->hasLocalLinkage(), true,
5525-
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
5531+
Var->hasLocalLinkage(), true, E,
55265532
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
55275533
Align, Annotations);
55285534
Var->addDebugInfo(GVE);

clang/test/CodeGenCXX/debug-info-static-inline-member.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main() {
4343
// CHECK: @{{.*}}cexpr_struct_with_addr{{.*}} =
4444
// CHECK-SAME !dbg ![[EMPTY_GLOBAL:[0-9]+]]
4545

46-
// CHECK: !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: !DIExpression())
46+
// CHECK: !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 25, DW_OP_stack_value))
4747
// CHECK: ![[INT_VAR]] = distinct !DIGlobalVariable(name: "cexpr_int_with_addr", linkageName:
4848
// CHECK-SAME: isLocal: false, isDefinition: true, declaration: ![[INT_DECL:[0-9]+]])
4949

clang/test/CodeGenCXX/inline-dllexport-member.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct __declspec(dllexport) s {
77
static const unsigned int ui = 0;
88
};
99

10-
// CHECK: [[UI]] = !DIGlobalVariableExpression(var: [[UIV:.*]], expr: !DIExpression())
10+
// CHECK: [[UI]] = !DIGlobalVariableExpression(var: [[UIV:.*]], expr: !DIExpression(DW_OP_constu, 0, DW_OP_stack_value))
1111
// CHECK: [[UIV]] = distinct !DIGlobalVariable(name: "ui", linkageName: "?ui@s@@2IB", scope: ![[SCOPE:[0-9]+]],
1212
// CHECK: ![[SCOPE]] = distinct !DICompileUnit(
1313

0 commit comments

Comments
 (0)