r268055 - Recommitted r264281 "Supporting all entities declared in lexical scope in LLVM debug info."

Pete Cooper via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 29 10:35:03 PDT 2016


> On Apr 29, 2016, at 10:27 AM, Aboud, Amjad <amjad.aboud at intel.com> wrote:
> 
> Sorry for that, I broke a LIT test that I added few days ago.
> The LIT test need to be fixed and I already fixed it in r268063.
No problem.  Thanks for the quick reply.
>  
> Let’s wait till r268063 run bots and see that everything will pass.
Sounds good, thanks.  I’ll keep an eye on the bots.

Thanks,
Pete
>   <>
> Thanks,
> Amjad
>  <>From: peter_cooper at apple.com [mailto:peter_cooper at apple.com] 
> Sent: Friday, April 29, 2016 19:53
> To: Aboud, Amjad <amjad.aboud at intel.com>
> Cc: cfe-commits at lists.llvm.org
> Subject: Re: r268055 - Recommitted r264281 "Supporting all entities declared in lexical scope in LLVM debug info."
>  
> Hi Amjad
>  
> Either this change, or r268054, appears to have broken the bots.  Can you please take a look?
>  
> The error at: http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/22409/consoleFull#8333002949ba4694-19c4-4d7e-bec5-911270d8a58c <http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/22409/consoleFull#8333002949ba4694-19c4-4d7e-bec5-911270d8a58c>
>  
> Thanks,
> Pete
> On Apr 29, 2016, at 9:08 AM, Amjad Aboud via cfe-commits <cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>> wrote:
>  
> Author: aaboud
> Date: Fri Apr 29 11:08:08 2016
> New Revision: 268055
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=268055&view=rev <http://llvm.org/viewvc/llvm-project?rev=268055&view=rev>
> Log:
> Recommitted r264281 "Supporting all entities declared in lexical scope in LLVM debug info."
> After fixing PR26942 in r267004.
> 
> Added:
>    cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp
> Modified:
>    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>    cfe/trunk/lib/CodeGen/CGDebugInfo.h
>    cfe/trunk/lib/CodeGen/CGDecl.cpp
>    cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=268055&r1=268054&r2=268055&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=268055&r1=268054&r2=268055&view=diff>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 29 11:08:08 2016
> @@ -814,15 +814,18 @@ llvm::DIType *CGDebugInfo::CreateType(co
> 
> llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
>                                       llvm::DIFile *Unit) {
> +  TypedefNameDecl *TD = Ty->getDecl();
>   // We don't set size information, but do specify where the typedef was
>   // declared.
> -  SourceLocation Loc = Ty->getDecl()->getLocation();
> +  SourceLocation Loc = TD->getLocation();
> +
> +  llvm::DIScope *TDContext = getDeclarationLexicalScope(*TD, QualType(Ty, 0));
> 
>   // Typedefs are derived from some other type.
>   return DBuilder.createTypedef(
>       getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
>       Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
> -      getDeclContextDescriptor(Ty->getDecl()));
> +      TDContext);
> }
> 
> llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
> @@ -1457,6 +1460,23 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
>   return T;
> }
> 
> +void CGDebugInfo::recordDeclarationLexicalScope(const Decl &D) {
> +  assert(LexicalBlockMap.find(&D) == LexicalBlockMap.end() &&
> +         "D is already mapped to lexical block scope");
> +  if (!LexicalBlockStack.empty())
> +    LexicalBlockMap[&D] = LexicalBlockStack.back();
> +}
> +
> +llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl &D,
> +                                                       QualType Ty) {
> +  auto I = LexicalBlockMap.find(&D);
> +  if (I != LexicalBlockMap.end()) {
> +    RetainedTypes.push_back(Ty.getAsOpaquePtr());
> +    return I->second;
> +  }
> +  return getDeclContextDescriptor(cast<Decl>(&D));
> +}
> +
> void CGDebugInfo::completeType(const EnumDecl *ED) {
>   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
>     return;
> @@ -2060,7 +2080,7 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp
>     // entered into the ReplaceMap: finalize() will replace the first
>     // FwdDecl with the second and then replace the second with
>     // complete type.
> -    llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
> +    llvm::DIScope *EDContext = getDeclarationLexicalScope(*ED, QualType(Ty, 0));
>     llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
>     llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
>         llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
> @@ -2104,7 +2124,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDef
> 
>   llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
>   unsigned Line = getLineNumber(ED->getLocation());
> -  llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
> +  llvm::DIScope *EnumContext = getDeclarationLexicalScope(*ED, QualType(Ty, 0));
>   llvm::DIType *ClassTy =
>       ED->isFixed() ? getOrCreateType(ED->getIntegerType(), DefUnit) : nullptr;
>   return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
> @@ -2365,7 +2385,7 @@ llvm::DICompositeType *CGDebugInfo::Crea
>   unsigned Line = getLineNumber(RD->getLocation());
>   StringRef RDName = getClassName(RD);
> 
> -  llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
> +  llvm::DIScope *RDContext = getDeclarationLexicalScope(*RD, QualType(Ty, 0));
> 
>   // If we ended up creating the type during the context chain construction,
>   // just return that.
> @@ -2536,8 +2556,15 @@ void CGDebugInfo::collectVarDeclProps(co
>   if (DC->isRecord())
>     DC = CGM.getContext().getTranslationUnitDecl();
> 
> - llvm::DIScope *Mod = getParentModuleOrNull(VD);
> - VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
> +  if (VD->isStaticLocal()) {
> +    // Get context for static locals (that are technically globals) the same way
> +    // we do for "local" locals -- by using current lexical block.
> +    assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
> +    VDContext = LexicalBlockStack.back();
> +  } else {
> +    llvm::DIScope *Mod = getParentModuleOrNull(VD);
> +    VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
> +  }
> }
> 
> llvm::DISubprogram *
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=268055&r1=268054&r2=268055&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=268055&r1=268054&r2=268055&view=diff>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Fri Apr 29 11:08:08 2016
> @@ -107,6 +107,11 @@ 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
> @@ -369,6 +374,12 @@ 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, QualType Ty);
> +
>   /// Emit standalone debug info for a type.
>   llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
> 
> 
> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=268055&r1=268054&r2=268055&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=268055&r1=268054&r2=268055&view=diff>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Fri Apr 29 11:08:08 2016
> @@ -87,11 +87,7 @@ void CodeGenFunction::EmitDecl(const Dec
>   case Decl::UsingShadow:
>   case Decl::ObjCTypeParam:
>     llvm_unreachable("Declaration should not be in declstmts!");
> -  case Decl::Function:  // void X();
> -  case Decl::Record:    // struct/union/class X;
> -  case Decl::Enum:      // enum X;
> -  case Decl::EnumConstant: // enum ? { X = ? }
> -  case Decl::CXXRecord: // struct/union/class X; [C++]
> +  case Decl::Function:     // void X();
>   case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
>   case Decl::Label:        // __label__ x;
>   case Decl::Import:
> @@ -101,13 +97,21 @@ void CodeGenFunction::EmitDecl(const Dec
>     // None of these decls require codegen support.
>     return;
> 
> +  case Decl::Record:       // struct/union/class X;
> +  case Decl::Enum:         // enum X;
> +  case Decl::EnumConstant: // enum ? { X = ? }
> +  case Decl::CXXRecord:    // struct/union/class X; [C++]
> +    if (CGDebugInfo *DI = getDebugInfo())
> +      DI->recordDeclarationLexicalScope(D);
> +    return;
> +
>   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::UsingDirective: // using namespace X; [C++]
>     if (CGDebugInfo *DI = getDebugInfo())
> @@ -128,6 +132,9 @@ void CodeGenFunction::EmitDecl(const Dec
>     const TypedefNameDecl &TD = cast<TypedefNameDecl>(D);
>     QualType Ty = TD.getUnderlyingType();
> 
> +    if (CGDebugInfo *DI = getDebugInfo())
> +      DI->recordDeclarationLexicalScope(D);
> +
>     if (Ty->isVariablyModifiedType())
>       EmitVariablyModifiedType(Ty);
>   }
> 
> Modified: cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp?rev=268055&r1=268054&r2=268055&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp?rev=268055&r1=268054&r2=268055&view=diff>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp Fri Apr 29 11:08:08 2016
> @@ -44,8 +44,13 @@ void instantiate(int x) {
>   buildBytes(x);
> }
> 
> -// CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE:.*]], line: 6,{{.*}} isLocal: true, isDefinition: true
> -// CHECK: [[FILE]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
> +// CHECK: ![[UNION:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_union_type,
> +// CHECK-NOT: name:
> +// CHECK: elements
> +// CHECK: [[FILE:.*]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
> +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]],
> +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]],
> +// CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
> // CHECK: !DIGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
> // CHECK: !DIGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
> // CHECK: !DIGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
> @@ -55,9 +60,4 @@ void instantiate(int x) {
> // CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial
> // CHECK: !DILocalVariable(
> // CHECK-NOT: name:
> -// CHECK: type: ![[UNION:[0-9]+]]
> -// CHECK: ![[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
> -// CHECK-NOT: name:
> -// CHECK: elements
> -// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]],
> -// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]],
> +// CHECK: type: ![[UNION]]
> 
> Added: cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp?rev=268055&view=auto <http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp?rev=268055&view=auto>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp Fri Apr 29 11:08:08 2016
> @@ -0,0 +1,27 @@
> +// 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 !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: [[LBScope:![0-9]+]],
> +// CHECK: [[LBScope]] = distinct !DILexicalBlock(scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: 5)
> +
> +// CHECK: [[FuncScope:![0-9]+]] = distinct !DISubprogram(name: "foo",
> +
> +// CHECK: !{{[0-9]+}} = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: [[LBScope]],
> +// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[FuncScope]], file: !{{[0-9]+}}, line: 4
> +// CHECK: !{{[0-9]+}} = distinct !DIGlobalVariable(name: "bar", scope: [[LBScope]], file: !{{[0-9]+}}, line: 8
> +
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits>
>  
> ---------------------------------------------------------------------
> Intel Israel (74) Limited
> 
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160429/62137f76/attachment-0001.html>


More information about the cfe-commits mailing list