Revert "[clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block"

This reverts commit e403f4fdc8 because it
breaks TestSetData.py on GreenDragon:

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/39089/
This commit is contained in:
Jonas Devlieghere 2021-12-06 09:30:01 -08:00
parent acdbd34cfb
commit 4cb79294e8
4 changed files with 11 additions and 77 deletions

View File

@ -227,20 +227,6 @@ llvm::DIScope *CGDebugInfo::getContextDescriptor(const Decl *Context,
return Default;
}
void CGDebugInfo::recordDeclarationLexicalScope(const Decl &D) {
assert(LexicalBlockMap.find(&D) == LexicalBlockMap.end() &&
"D is already mapped to a lexical block scope");
if (!LexicalBlockStack.empty())
LexicalBlockMap.insert({&D, LexicalBlockStack.back()});
}
llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl *D) {
auto I = LexicalBlockMap.find(D);
if (I != LexicalBlockMap.end())
return I->second;
return getDeclContextDescriptor(cast<Decl>(D));
}
PrintingPolicy CGDebugInfo::getPrintingPolicy() const {
PrintingPolicy PP = CGM.getContext().getPrintingPolicy();
@ -1360,13 +1346,13 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
// declared.
SourceLocation Loc = Ty->getDecl()->getLocation();
llvm::DIScope *TDContext = getDeclarationLexicalScope(Ty->getDecl());
uint32_t Align = getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext());
// Typedefs are derived from some other type.
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(Ty->getDecl());
return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
getOrCreateFile(Loc), getLineNumber(Loc),
TDContext, Align, Annotations);
getDeclContextDescriptor(Ty->getDecl()), Align,
Annotations);
}
static unsigned getDwarfCC(CallingConv CC) {
@ -3265,7 +3251,7 @@ llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) {
// entered into the ReplaceMap: finalize() will replace the first
// FwdDecl with the second and then replace the second with
// complete type.
llvm::DIScope *EDContext = getDeclarationLexicalScope(ED);
llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
@ -3308,7 +3294,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
unsigned Line = getLineNumber(ED->getLocation());
llvm::DIScope *EnumContext = getDeclarationLexicalScope(ED);
llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
@ -3611,7 +3597,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
Line = getLineNumber(Loc);
}
llvm::DIScope *RDContext = getDeclarationLexicalScope(RD);
llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
// If we ended up creating the type during the context chain construction,
// just return that.
@ -3804,14 +3790,6 @@ void CGDebugInfo::collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
TemplateParameters = nullptr;
}
// Get context for static locals (that are technically globals) the same way
// we do for "local" locals -- by using current lexical block.
if (VD->isStaticLocal()) {
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
VDContext = LexicalBlockStack.back();
return;
}
// Since we emit declarations (DW_AT_members) for static members, place the
// definition of those static members in the namespace they were declared in
// in the source code (the lexical decl context).

View File

@ -139,11 +139,6 @@ class CGDebugInfo {
/// Keep track of our current nested lexical block.
std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
/// Map of AST declaration to its lexical block scope.
llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIScope>>
LexicalBlockMap;
llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
/// Keep track of LexicalBlockStack counter at the beginning of a
/// function. This is used to pop unbalanced regions at the end of a
@ -548,12 +543,6 @@ public:
/// Emit an Objective-C interface type standalone debug info.
llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
/// Map AST declaration to its lexical block scope if available.
void recordDeclarationLexicalScope(const Decl &D);
/// Get lexical scope of AST declaration.
llvm::DIScope *getDeclarationLexicalScope(const Decl *D);
/// Emit standalone debug info for a type.
llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);

View File

@ -103,21 +103,17 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
llvm_unreachable("Declaration should not be in declstmts!");
case Decl::Record: // struct/union/class X;
case Decl::CXXRecord: // struct/union/class X; [C++]
if (CGDebugInfo *DI = getDebugInfo()) {
DI->recordDeclarationLexicalScope(D);
if (CGDebugInfo *DI = getDebugInfo())
if (cast<RecordDecl>(D).getDefinition())
DI->EmitAndRetainType(getContext().getRecordType(cast<RecordDecl>(&D)));
}
return;
case Decl::Enum: // enum X;
if (CGDebugInfo *DI = getDebugInfo()) {
DI->recordDeclarationLexicalScope(D);
if (CGDebugInfo *DI = getDebugInfo())
if (cast<EnumDecl>(D).getDefinition())
DI->EmitAndRetainType(getContext().getEnumType(cast<EnumDecl>(&D)));
}
return;
case Decl::EnumConstant: // enum ? { X = ? }
case Decl::Function: // void X();
case Decl::EnumConstant: // enum ? { X = ? }
case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
case Decl::Label: // __label__ x;
case Decl::Import:
@ -136,11 +132,11 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
case Decl::NamespaceAlias:
if (CGDebugInfo *DI = getDebugInfo())
DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(D));
return;
case Decl::Using: // using X; [C++]
if (CGDebugInfo *DI = getDebugInfo())
DI->EmitUsingDecl(cast<UsingDecl>(D));
DI->EmitUsingDecl(cast<UsingDecl>(D));
return;
case Decl::UsingEnum: // using enum X; [C++]
if (CGDebugInfo *DI = getDebugInfo())
@ -176,10 +172,8 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
case Decl::Typedef: // typedef int X;
case Decl::TypeAlias: { // using X = int; [C++0x]
QualType Ty = cast<TypedefNameDecl>(D).getUnderlyingType();
if (CGDebugInfo *DI = getDebugInfo()) {
DI->recordDeclarationLexicalScope(D);
if (CGDebugInfo *DI = getDebugInfo())
DI->EmitAndRetainType(Ty);
}
if (Ty->isVariablyModifiedType())
EmitVariablyModifiedType(Ty);
return;

View File

@ -1,27 +0,0 @@
// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
void foo() {
static int bar = 1;
{
struct X {};
typedef char Y;
static int bar = 0;
// The following basic block is intended, in order to check the case where
// types "X", "Y" are defined in a different scope than where they are used.
// They should have the scope they are defined at as their parent scope.
{
X a;
Y b;
}
}
}
// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]]
// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "foo"
// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBSCOPE:![0-9]+]]
// CHECK: [[LBSCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]]
// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "a", scope: [[LBSCOPE2:![0-9]+]], {{.*}} type: [[STRUCT:![0-9]+]]
// CHECK: [[LBSCOPE2]] = distinct !DILexicalBlock(scope: [[LBSCOPE]]
// CHECK: [[STRUCT]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBSCOPE]]
// CHECK: !{{[0-9]+}} = !DILocalVariable(name: "b", scope: [[LBSCOPE2]], {{.*}} type: [[TYPEDEF:![0-9]+]]
// CHECK: [[TYPEDEF]] = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBSCOPE]]