Skip to content

Commit 4cb7929

Browse files
committed
Revert "[clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block"
This reverts commit e403f4f because it breaks TestSetData.py on GreenDragon: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/39089/
1 parent acdbd34 commit 4cb7929

File tree

4 files changed

+11
-77
lines changed

4 files changed

+11
-77
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,6 @@ llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context,
227227
return Default;
228228
}
229229

230-
void CGDebugInfo::recordDeclarationLexicalScope(const Decl &D) {
231-
assert(LexicalBlockMap.find(&D) == LexicalBlockMap.end() &&
232-
"D is already mapped to a lexical block scope");
233-
if (!LexicalBlockStack.empty())
234-
LexicalBlockMap.insert({&D, LexicalBlockStack.back()});
235-
}
236-
237-
llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl *D) {
238-
auto I = LexicalBlockMap.find(D);
239-
if (I != LexicalBlockMap.end())
240-
return I->second;
241-
return getDeclContextDescriptor(cast<Decl>(D));
242-
}
243-
244230
PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
245231
PrintingPolicy PP = CGM.getContext().getPrintingPolicy();
246232

@@ -1360,13 +1346,13 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
13601346
// declared.
13611347
SourceLocation Loc = Ty->getDecl()->getLocation();
13621348

1363-
llvm::DIScope *TDContext = getDeclarationLexicalScope(Ty->getDecl());
13641349
uint32_t Align = getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext());
13651350
// Typedefs are derived from some other type.
13661351
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(Ty->getDecl());
13671352
return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
13681353
getOrCreateFile(Loc), getLineNumber(Loc),
1369-
TDContext, Align, Annotations);
1354+
getDeclContextDescriptor(Ty->getDecl()), Align,
1355+
Annotations);
13701356
}
13711357

13721358
static unsigned getDwarfCC(CallingConv CC) {
@@ -3265,7 +3251,7 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) {
32653251
// entered into the ReplaceMap: finalize() will replace the first
32663252
// FwdDecl with the second and then replace the second with
32673253
// complete type.
3268-
llvm::DIScope *EDContext = getDeclarationLexicalScope(ED);
3254+
llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
32693255
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
32703256
llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
32713257
llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
@@ -3308,7 +3294,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
33083294

33093295
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
33103296
unsigned Line = getLineNumber(ED->getLocation());
3311-
llvm::DIScope *EnumContext = getDeclarationLexicalScope(ED);
3297+
llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
33123298
llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
33133299
return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
33143300
Line, Size, Align, EltArray, ClassTy,
@@ -3611,7 +3597,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
36113597
Line = getLineNumber(Loc);
36123598
}
36133599

3614-
llvm::DIScope *RDContext = getDeclarationLexicalScope(RD);
3600+
llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
36153601

36163602
// If we ended up creating the type during the context chain construction,
36173603
// just return that.
@@ -3804,14 +3790,6 @@ void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
38043790
TemplateParameters = nullptr;
38053791
}
38063792

3807-
// Get context for static locals (that are technically globals) the same way
3808-
// we do for "local" locals -- by using current lexical block.
3809-
if (VD->isStaticLocal()) {
3810-
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
3811-
VDContext = LexicalBlockStack.back();
3812-
return;
3813-
}
3814-
38153793
// Since we emit declarations (DW_AT_members) for static members, place the
38163794
// definition of those static members in the namespace they were declared in
38173795
// in the source code (the lexical decl context).

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@ class CGDebugInfo {
139139

140140
/// Keep track of our current nested lexical block.
141141
std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
142-
143-
/// Map of AST declaration to its lexical block scope.
144-
llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIScope>>
145-
LexicalBlockMap;
146-
147142
llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
148143
/// Keep track of LexicalBlockStack counter at the beginning of a
149144
/// function. This is used to pop unbalanced regions at the end of a
@@ -548,12 +543,6 @@ class CGDebugInfo {
548543
/// Emit an Objective-C interface type standalone debug info.
549544
llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
550545

551-
/// Map AST declaration to its lexical block scope if available.
552-
void recordDeclarationLexicalScope(const Decl &D);
553-
554-
/// Get lexical scope of AST declaration.
555-
llvm::DIScope *getDeclarationLexicalScope(const Decl *D);
556-
557546
/// Emit standalone debug info for a type.
558547
llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
559548

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,17 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
103103
llvm_unreachable("Declaration should not be in declstmts!");
104104
case Decl::Record: // struct/union/class X;
105105
case Decl::CXXRecord: // struct/union/class X; [C++]
106-
if (CGDebugInfo *DI = getDebugInfo()) {
107-
DI->recordDeclarationLexicalScope(D);
106+
if (CGDebugInfo *DI = getDebugInfo())
108107
if (cast<RecordDecl>(D).getDefinition())
109108
DI->EmitAndRetainType(getContext().getRecordType(cast<RecordDecl>(&D)));
110-
}
111109
return;
112110
case Decl::Enum: // enum X;
113-
if (CGDebugInfo *DI = getDebugInfo()) {
114-
DI->recordDeclarationLexicalScope(D);
111+
if (CGDebugInfo *DI = getDebugInfo())
115112
if (cast<EnumDecl>(D).getDefinition())
116113
DI->EmitAndRetainType(getContext().getEnumType(cast<EnumDecl>(&D)));
117-
}
118114
return;
119-
case Decl::EnumConstant: // enum ? { X = ? }
120115
case Decl::Function: // void X();
116+
case Decl::EnumConstant: // enum ? { X = ? }
121117
case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
122118
case Decl::Label: // __label__ x;
123119
case Decl::Import:
@@ -136,11 +132,11 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
136132

137133
case Decl::NamespaceAlias:
138134
if (CGDebugInfo *DI = getDebugInfo())
139-
DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
135+
DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
140136
return;
141137
case Decl::Using: // using X; [C++]
142138
if (CGDebugInfo *DI = getDebugInfo())
143-
DI->EmitUsingDecl(cast<UsingDecl>(D));
139+
DI->EmitUsingDecl(cast<UsingDecl>(D));
144140
return;
145141
case Decl::UsingEnum: // using enum X; [C++]
146142
if (CGDebugInfo *DI = getDebugInfo())
@@ -176,10 +172,8 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
176172
case Decl::Typedef: // typedef int X;
177173
case Decl::TypeAlias: { // using X = int; [C++0x]
178174
QualType Ty = cast<TypedefNameDecl>(D).getUnderlyingType();
179-
if (CGDebugInfo *DI = getDebugInfo()) {
180-
DI->recordDeclarationLexicalScope(D);
175+
if (CGDebugInfo *DI = getDebugInfo())
181176
DI->EmitAndRetainType(Ty);
182-
}
183177
if (Ty->isVariablyModifiedType())
184178
EmitVariablyModifiedType(Ty);
185179
return;

clang/test/CodeGenCXX/debug-info-lexcial-block.cpp

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

0 commit comments

Comments
 (0)