Skip to content

Commit 333124c

Browse files
committed
Revert "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers (#70639)"
This reverts commit 4909814. Following LLDB patch had to be reverted due to Linux test failures: ``` ef3feba ``` Since without that LLDB patch the LLDB tests would fail, revert this clang patch for now.
1 parent 5f86b49 commit 333124c

File tree

7 files changed

+42
-197
lines changed

7 files changed

+42
-197
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,13 +1677,22 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, llvm::DIType *RecordTy,
16771677

16781678
unsigned LineNumber = getLineNumber(Var->getLocation());
16791679
StringRef VName = Var->getName();
1680+
llvm::Constant *C = nullptr;
1681+
if (Var->getInit()) {
1682+
const APValue *Value = Var->evaluateValue();
1683+
if (Value) {
1684+
if (Value->isInt())
1685+
C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
1686+
if (Value->isFloat())
1687+
C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
1688+
}
1689+
}
16801690

16811691
llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
16821692
auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
16831693
llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1684-
RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, Align);
1694+
RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align);
16851695
StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
1686-
StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
16871696
return GV;
16881697
}
16891698

@@ -5587,39 +5596,6 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
55875596
TemplateParameters, Align));
55885597
}
55895598

5590-
void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
5591-
assert(VD->hasInit());
5592-
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5593-
if (VD->hasAttr<NoDebugAttr>())
5594-
return;
5595-
5596-
auto &GV = DeclCache[VD];
5597-
if (GV)
5598-
return;
5599-
5600-
auto const *InitVal = VD->evaluateValue();
5601-
if (!InitVal)
5602-
return;
5603-
5604-
llvm::DIFile *Unit = nullptr;
5605-
llvm::DIScope *DContext = nullptr;
5606-
unsigned LineNo;
5607-
StringRef DeclName, LinkageName;
5608-
QualType T;
5609-
llvm::MDTuple *TemplateParameters = nullptr;
5610-
collectVarDeclProps(VD, Unit, LineNo, T, DeclName, LinkageName,
5611-
TemplateParameters, DContext);
5612-
5613-
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
5614-
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5615-
llvm::DIExpression *InitExpr = createConstantValueExpression(VD, *InitVal);
5616-
5617-
GV.reset(DBuilder.createGlobalVariableExpression(
5618-
TheCU, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
5619-
true, true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VD),
5620-
TemplateParameters, Align, Annotations));
5621-
}
5622-
56235599
void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
56245600
const VarDecl *D) {
56255601
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
@@ -5890,18 +5866,6 @@ void CGDebugInfo::finalize() {
58905866
DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
58915867
}
58925868

5893-
for (auto const *VD : StaticDataMemberDefinitionsToEmit) {
5894-
assert(VD->isStaticDataMember());
5895-
5896-
if (DeclCache.contains(VD))
5897-
continue;
5898-
5899-
if (!VD->hasInit())
5900-
continue;
5901-
5902-
EmitGlobalVariable(VD);
5903-
}
5904-
59055869
// We keep our own list of retained types, because we need to look
59065870
// up the final type in the type cache.
59075871
for (auto &RT : RetainedTypes)

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ class CGDebugInfo {
161161
llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
162162
StaticDataMemberCache;
163163

164-
/// Keeps track of static data members for which we should emit a definition.
165-
std::vector<const VarDecl *> StaticDataMemberDefinitionsToEmit;
166-
167164
using ParamDecl2StmtTy = llvm::DenseMap<const ParmVarDecl *, const Stmt *>;
168165
using Param2DILocTy =
169166
llvm::DenseMap<const ParmVarDecl *, llvm::DILocalVariable *>;
@@ -529,9 +526,6 @@ class CGDebugInfo {
529526
/// Emit a constant global variable's debug info.
530527
void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
531528

532-
/// Emit debug-info for a variable with a constant initializer.
533-
void EmitGlobalVariable(const VarDecl *VD);
534-
535529
/// Emit information about an external variable.
536530
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
537531

clang/test/CodeGenCXX/debug-info-class.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,11 @@ int main(int argc, char **argv) {
116116
// CHECK-SAME: DIFlagFwdDecl
117117
// CHECK-NOT: identifier:
118118
// CHECK-SAME: ){{$}}
119-
120-
// CHECK: !DIGlobalVariableExpression(var: ![[HDR_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 52, DW_OP_stack_value))
121-
// CHECK: ![[HDR_VAR]] = distinct !DIGlobalVariable(name: "HdrSize",
122-
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[HDR_VAR_DECL:[0-9]+]])
123-
// CHECK: ![[INT:[0-9]+]] = !DIBasicType(name: "int"
124-
// CHECK: ![[HDR_VAR_DECL]] = !DIDerivedType(tag: DW_TAG_member, name: "HdrSize"
125-
126-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
127-
128119
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "I"
129120
// CHECK-NOT: DIFlagFwdDecl
130121
// CHECK-SAME: ){{$}}
131122

123+
// CHECK: ![[INT:[0-9]+]] = !DIBasicType(name: "int"
132124
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "foo"
133125
// CHECK: !DICompositeType(tag: DW_TAG_class_type, name: "bar"
134126
// CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "baz"
@@ -194,5 +186,8 @@ int main(int argc, char **argv) {
194186
// CHECK: [[G_INNER_I]] = !DIDerivedType(tag: DW_TAG_member, name: "j"
195187
// CHECK-SAME: baseType: ![[INT]]
196188

189+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "A"
190+
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "HdrSize"
191+
//
197192
// CHECK: ![[EXCEPTLOC]] = !DILocation(line: 100,
198193
// CHECK: ![[RETLOC]] = !DILocation(line: 99,

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

Lines changed: 0 additions & 94 deletions
This file was deleted.

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

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,32 @@ int C::a = 4;
6363
// CHECK-NOT: offset:
6464
// CHECK-SAME: flags: DIFlagStaticMember)
6565
//
66-
// CHECK: ![[CONST_A_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "const_a"
67-
// CHECK-NOT: size:
68-
// CHECK-NOT: align:
69-
// CHECK-NOT: offset:
70-
// CHECK-SAME: flags: DIFlagStaticMember
71-
// CHECK-NOT: extraData:
72-
73-
// CHECK: ![[CONST_B_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "const_b"
74-
// CHECK-NOT: size:
75-
// CHECK-NOT: align:
76-
// CHECK-NOT: offset:
77-
// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember
78-
// CHECK-NOT: extraData:
66+
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_a"
67+
// CHECK-NOT: size:
68+
// CHECK-NOT: align:
69+
// CHECK-NOT: offset:
70+
// CHECK-SAME: flags: DIFlagStaticMember,
71+
// CHECK-SAME: extraData: i1 true)
72+
73+
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_b"
74+
// CHECK-NOT: size:
75+
// CHECK-NOT: align:
76+
// CHECK-NOT: offset:
77+
// CHECK-SAME: flags: DIFlagProtected | DIFlagStaticMember,
78+
// CHECK-SAME: extraData: float 0x{{.*}})
7979

8080
// CHECK: ![[DECL_C:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "c"
8181
// CHECK-NOT: size:
8282
// CHECK-NOT: align:
8383
// CHECK-NOT: offset:
8484
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
8585
//
86-
// CHECK: ![[CONST_C_DECL:[0-9]+]] = !DIDerivedType(tag: DW_TAG_member, name: "const_c"
87-
// CHECK-NOT: size:
88-
// CHECK-NOT: align:
89-
// CHECK-NOT: offset:
90-
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember
91-
// CHECK-NOT: extraData:
86+
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "const_c"
87+
// CHECK-NOT: size:
88+
// CHECK-NOT: align:
89+
// CHECK-NOT: offset:
90+
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember,
91+
// CHECK-SAME: extraData: i32 18)
9292
//
9393
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x_a"
9494
// CHECK-SAME: flags: DIFlagPublic | DIFlagStaticMember)
@@ -144,7 +144,7 @@ struct V {
144144
// const_va is not emitted for MS targets.
145145
// NOT-MS: !DIDerivedType(tag: DW_TAG_member, name: "const_va",
146146
// NOT-MS-SAME: line: [[@LINE-5]]
147-
// NOT-MS-NOT: extraData:
147+
// NOT-MS-SAME: extraData: i32 42
148148
const int V::const_va;
149149

150150
namespace x {
@@ -156,15 +156,3 @@ struct y {
156156
};
157157
int y::z;
158158
}
159-
160-
// CHECK: !DIGlobalVariableExpression(var: ![[CONST_A_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 1, DW_OP_stack_value))
161-
// CHECK: ![[CONST_A_VAR]] = distinct !DIGlobalVariable(name: "const_a"
162-
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[CONST_A_DECL]])
163-
164-
// CHECK: !DIGlobalVariableExpression(var: ![[CONST_B_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, {{.*}}, DW_OP_stack_value))
165-
// CHECK: ![[CONST_B_VAR]] = distinct !DIGlobalVariable(name: "const_b"
166-
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[CONST_B_DECL]])
167-
168-
// CHECK: !DIGlobalVariableExpression(var: ![[CONST_C_VAR:[0-9]+]], expr: !DIExpression(DW_OP_constu, 18, DW_OP_stack_value))
169-
// CHECK: ![[CONST_C_VAR]] = distinct !DIGlobalVariable(name: "const_c"
170-
// CHECK-SAME: isLocal: true, isDefinition: true, declaration: ![[CONST_C_DECL]])

lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ def test(self):
102102
# it does not crash.
103103
self.expect("image lookup -t A")
104104

105-
# For debug-info produced by older versions of clang, dsymutil strips the
106-
# debug info for classes that only have const static data members without
107-
# definitions.
108-
@expectedFailureAll(compiler=["clang"], compiler_version=["<", "18.0"])
105+
# dsymutil strips the debug info for classes that only have const static
106+
# data members without a definition namespace scope.
107+
@expectedFailureAll(debug_info=["dsym"])
109108
def test_class_with_only_const_static(self):
110109
self.build()
111110
lldbutil.run_to_source_breakpoint(

lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ def verify_values(self, verify_dict, actual, varref_dict=None, expression=None):
8787
def verify_variables(self, verify_dict, variables, varref_dict=None):
8888
for variable in variables:
8989
name = variable["name"]
90-
if not name.startswith("std::"):
91-
self.assertIn(
92-
name, verify_dict, 'variable "%s" in verify dictionary' % (name)
93-
)
94-
self.verify_values(verify_dict[name], variable, varref_dict)
90+
self.assertIn(
91+
name, verify_dict, 'variable "%s" in verify dictionary' % (name)
92+
)
93+
self.verify_values(verify_dict[name], variable, varref_dict)
9594

9695
def darwin_dwarf_missing_obj(self, initCommands):
9796
self.build(debug_info="dwarf")

0 commit comments

Comments
 (0)