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

Jonas Devlieghere via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 6 09:34:57 PST 2021


Author: Jonas Devlieghere
Date: 2021-12-06T09:34:53-08:00
New Revision: 4cb79294e8df8c91ae15264d1014361815d34a53

URL: https://github.com/llvm/llvm-project/commit/4cb79294e8df8c91ae15264d1014361815d34a53
DIFF: https://github.com/llvm/llvm-project/commit/4cb79294e8df8c91ae15264d1014361815d34a53.diff

LOG: 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/

Added: 
    

Modified: 
    clang/lib/CodeGen/CGDebugInfo.cpp
    clang/lib/CodeGen/CGDebugInfo.h
    clang/lib/CodeGen/CGDecl.cpp

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


################################################################################
diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 75eec22e4e4e5..af651e6f44b7c 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<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).

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 1350ee6808cc2..a7b72fa5f5a65 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<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 @@ class CGDebugInfo {
   /// 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 742bc8eb3dbdb..941671c614824 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<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;

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 75b4b2c052bd3..0000000000000
--- 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 
diff erent 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]]


        


More information about the cfe-commits mailing list