From: Jonas Devlieghere Date: Mon, 6 Dec 2021 17:30:01 +0000 (-0800) Subject: Revert "[clang][DebugInfo] Allow function-local statics and types to be scoped within... X-Git-Tag: upstream/15.0.7~23880 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cb79294e8df8c91ae15264d1014361815d34a53;p=platform%2Fupstream%2Fllvm.git Revert "[clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block" This reverts commit e403f4fdc88322201040f2bee7b328e8a78e2f7f because it breaks TestSetData.py on GreenDragon: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/39089/ --- diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 75eec22..af651e6 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -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(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). diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 1350ee6..a7b72fa 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -139,11 +139,6 @@ class CGDebugInfo { /// Keep track of our current nested lexical block. std::vector> LexicalBlockStack; - - /// Map of AST declaration to its lexical block scope. - llvm::DenseMap> - LexicalBlockMap; - llvm::DenseMap 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); diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 742bc8e..941671c 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -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(D).getDefinition()) DI->EmitAndRetainType(getContext().getRecordType(cast(&D))); - } return; case Decl::Enum: // enum X; - if (CGDebugInfo *DI = getDebugInfo()) { - DI->recordDeclarationLexicalScope(D); + if (CGDebugInfo *DI = getDebugInfo()) if (cast(D).getDefinition()) DI->EmitAndRetainType(getContext().getEnumType(cast(&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(D)); + DI->EmitNamespaceAlias(cast(D)); return; case Decl::Using: // using X; [C++] if (CGDebugInfo *DI = getDebugInfo()) - DI->EmitUsingDecl(cast(D)); + DI->EmitUsingDecl(cast(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(D).getUnderlyingType(); - if (CGDebugInfo *DI = getDebugInfo()) { - DI->recordDeclarationLexicalScope(D); + if (CGDebugInfo *DI = getDebugInfo()) DI->EmitAndRetainType(Ty); - } if (Ty->isVariablyModifiedType()) EmitVariablyModifiedType(Ty); return; diff --git a/clang/test/CodeGenCXX/debug-info-lexcial-block.cpp b/clang/test/CodeGenCXX/debug-info-lexcial-block.cpp deleted file mode 100644 index 75b4b2c..0000000 --- a/clang/test/CodeGenCXX/debug-info-lexcial-block.cpp +++ /dev/null @@ -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]]