[llvm] r241176 - Revert "[DWARF] Fix debug info generation for function static variables, typedefs, and records"

David Blaikie dblaikie at gmail.com
Wed Jul 1 11:20:42 PDT 2015


On Wed, Jul 1, 2015 at 11:07 AM, David Blaikie <dblaikie at gmail.com> wrote:

> Author: dblaikie
> Date: Wed Jul  1 13:07:16 2015
> New Revision: 241176
>
> URL: http://llvm.org/viewvc/llvm-project?rev=241176&view=rev
> Log:
> Revert "[DWARF] Fix debug info generation for function static variables,
> typedefs, and records"
>
> Caused PR24008
>
> This reverts commit 37cb5f1c2db9f42d29f26b215585f56bb64ae4f5.
>

r241153 (and r241162)


>
> Removed:
>     llvm/trunk/test/DebugInfo/X86/lexical-block-pr19238.ll
> Modified:
>     llvm/trunk/include/llvm/ADT/iterator_range.h
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
>
> Modified: llvm/trunk/include/llvm/ADT/iterator_range.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/iterator_range.h?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/iterator_range.h (original)
> +++ llvm/trunk/include/llvm/ADT/iterator_range.h Wed Jul  1 13:07:16 2015
> @@ -53,7 +53,4 @@ template <typename T> iterator_range<T>
>  }
>  }
>
> -template <typename R>
> -bool empty(const R& r) { return begin(r) == end(r); }
> -
>  #endif
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Wed Jul  1
> 13:07:16 2015
> @@ -101,7 +101,7 @@ static const ConstantExpr *getMergedGlob
>
>  /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
>  DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
> -  const DIGlobalVariable *GV, DIE *ContextDIE) {
> +    const DIGlobalVariable *GV) {
>    // Check for pre-existence.
>    if (DIE *Die = getDIE(GV))
>      return Die;
> @@ -113,8 +113,7 @@ DIE *DwarfCompileUnit::getOrCreateGlobal
>
>    // Construct the context before querying for the existence of the DIE in
>    // case such construction creates the DIE.
> -  if (ContextDIE == nullptr)
> -    ContextDIE = getOrCreateContextDIE(GVContext);
> +  DIE *ContextDIE = getOrCreateContextDIE(GVContext);
>
>    // Add to map.
>    DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
> @@ -336,16 +335,17 @@ void DwarfCompileUnit::constructScopeDIE
>      // null and the children will be added to the scope DIE.
>      createScopeChildrenDIE(Scope, Children, &ChildScopeCount);
>
> -
> -    DwarfDebug::LocalDeclMapRange LocalDeclNodeRangeForScope(nullptr,
> nullptr);
> -    // Skip local decls in gmlt-like data.
> -    if (!includeMinimalInlineScopes())
> -      LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS);
> +    // Skip imported directives in gmlt-like data.
> +    if (!includeMinimalInlineScopes()) {
> +      // There is no need to emit empty lexical block DIE.
> +      for (const auto &E : DD->findImportedEntitiesForScope(DS))
> +        Children.push_back(
> +            constructImportedEntityDIE(cast<DIImportedEntity>(E.second)));
> +    }
>
>      // If there are only other scopes as children, put them directly in
> the
>      // parent instead, as this scope would serve no purpose.
> -    if (Children.size() == ChildScopeCount &&
> -        empty(LocalDeclNodeRangeForScope)) {
> +    if (Children.size() == ChildScopeCount) {
>        FinalChildren.insert(FinalChildren.end(),
>                             std::make_move_iterator(Children.begin()),
>                             std::make_move_iterator(Children.end()));
> @@ -353,15 +353,6 @@ void DwarfCompileUnit::constructScopeDIE
>      }
>      ScopeDIE = constructLexicalScopeDIE(Scope);
>      assert(ScopeDIE && "Scope DIE should not be null.");
> -
> -    for (const auto &DI : LocalDeclNodeRangeForScope) {
> -      if (auto *IE = dyn_cast<DIImportedEntity>(DI.second))
> -        Children.push_back(constructImportedEntityDIE(IE));
> -      else if (auto *GV = dyn_cast<DIGlobalVariable>(DI.second))
> -        getOrCreateGlobalVariableDIE(GV, ScopeDIE);
> -      else if (auto *RT = dyn_cast<DIType>(DI.second))
> -        getOrCreateTypeDIE(RT, ScopeDIE);
> -    }
>    }
>
>    // Add children
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h Wed Jul  1
> 13:07:16 2015
> @@ -77,11 +77,8 @@ public:
>    /// Apply the DW_AT_stmt_list from this compile unit to the specified
> DIE.
>    void applyStmtList(DIE &D);
>
> -  /// Get or create global variable DIE.
> -  /// \param GV Global Variable Node
> -  /// \param ContextDIE DIE scope for GV Node, if available.
> -  DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV,
> -                                    DIE *ContextDIE = nullptr);
> +  /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
> +  DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV);
>
>    /// addLabelAddress - Add a dwarf label attribute data and value using
>    /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Jul  1 13:07:16
> 2015
> @@ -449,14 +449,14 @@ void DwarfDebug::beginModule() {
>      auto *CUNode = cast<DICompileUnit>(N);
>      DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
>      for (auto *IE : CUNode->getImportedEntities())
> -      ScopesWithLocalDeclNodes.push_back(std::make_pair(IE->getScope(),
> IE));
> -    for (auto *GV : CUNode->getGlobalVariables()) {
> -      auto *Context = GV->getScope();
> -      if (Context && isa<DILexicalBlockBase>(Context))
> -        ScopesWithLocalDeclNodes.push_back(std::make_pair(Context, GV));
> -      else
> -        CU.getOrCreateGlobalVariableDIE(GV);
> -    }
> +      ScopesWithImportedEntities.push_back(std::make_pair(IE->getScope(),
> IE));
> +    // Stable sort to preserve the order of appearance of imported
> entities.
> +    // This is to avoid out-of-order processing of interdependent
> declarations
> +    // within the same scope, e.g. { namespace A = base; namespace B = A;
> }
> +    std::stable_sort(ScopesWithImportedEntities.begin(),
> +                     ScopesWithImportedEntities.end(), less_first());
> +    for (auto *GV : CUNode->getGlobalVariables())
> +      CU.getOrCreateGlobalVariableDIE(GV);
>      for (auto *SP : CUNode->getSubprograms())
>        SPMap.insert(std::make_pair(SP, &CU));
>      for (auto *Ty : CUNode->getEnumTypes()) {
> @@ -467,23 +467,12 @@ void DwarfDebug::beginModule() {
>      for (auto *Ty : CUNode->getRetainedTypes()) {
>        // The retained types array by design contains pointers to
>        // MDNodes rather than DIRefs. Unique them here.
> -      DIType *RT = cast<DIType>(resolve(Ty->getRef()));
> -      auto *Context = resolve(Ty->getScope());
> -      if (Context && isa<DILexicalBlockBase>(Context))
> -        ScopesWithLocalDeclNodes.push_back(std::make_pair(Context, RT));
> -      else
> -        CU.getOrCreateTypeDIE(RT);
> +      CU.getOrCreateTypeDIE(cast<DIType>(resolve(Ty->getRef())));
>      }
>      // Emit imported_modules last so that the relevant context is already
>      // available.
>      for (auto *IE : CUNode->getImportedEntities())
>        constructAndAddImportedEntityDIE(CU, IE);
> -
> -    // Stable sort to preserve the order of appearance of imported
> entities.
> -    // This is to avoid out-of-order processing of interdependent
> declarations
> -    // within the same scope, e.g. { namespace A = base; namespace B = A;
> }
> -    std::stable_sort(ScopesWithLocalDeclNodes.begin(),
> -                     ScopesWithLocalDeclNodes.end(), less_first());
>    }
>
>    // Tell MMI that we have debug info.
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Wed Jul  1 13:07:16 2015
> @@ -278,10 +278,13 @@ class DwarfDebug : public AsmPrinterHand
>    // Holder for the file specific debug information.
>    DwarfFile InfoHolder;
>
> -  // Holder for local declaration DI nodes per scope.
> +  // Holders for the various debug information flags that we might need to
> +  // have exposed. See accessor functions below for description.
> +
> +  // Holder for imported entities.
>    typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
> -  LocalDeclMap;
> -  LocalDeclMap ScopesWithLocalDeclNodes;
> +  ImportedEntityMap;
> +  ImportedEntityMap ScopesWithImportedEntities;
>
>    // Map from MDNodes for user-defined types to the type units that
> describe
>    // them.
> @@ -616,12 +619,10 @@ public:
>
>    const MachineFunction *getCurrentFunction() const { return CurFn; }
>
> -  typedef iterator_range<LocalDeclMap::const_iterator> LocalDeclMapRange;
> -
> -  LocalDeclMapRange findLocalDeclNodesForScope(const MDNode *Scope) const
> {
> -    assert(DILexicalBlockBase::classof(Scope) && "Expected LexicalBlock
> scope");
> +  iterator_range<ImportedEntityMap::const_iterator>
> +  findImportedEntitiesForScope(const MDNode *Scope) const {
>      return make_range(std::equal_range(
> -        ScopesWithLocalDeclNodes.begin(), ScopesWithLocalDeclNodes.end(),
> +        ScopesWithImportedEntities.begin(),
> ScopesWithImportedEntities.end(),
>          std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
>          less_first()));
>    }
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Wed Jul  1 13:07:16
> 2015
> @@ -704,7 +704,7 @@ DIE *DwarfUnit::createTypeDIE(const DICo
>    return &TyDIE;
>  }
>
> -DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode, DIE *ContextDIE)
> {
> +DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
>    if (!TyNode)
>      return nullptr;
>
> @@ -714,20 +714,17 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const
>
>    // DW_TAG_restrict_type is not supported in DWARF2
>    if (Ty->getTag() == dwarf::DW_TAG_restrict_type &&
> DD->getDwarfVersion() <= 2)
> -    return
> getOrCreateTypeDIE(resolve(cast<DIDerivedType>(Ty)->getBaseType()),
> -                              ContextDIE);
> +    return
> getOrCreateTypeDIE(resolve(cast<DIDerivedType>(Ty)->getBaseType()));
>
>    // Construct the context before querying for the existence of the DIE
> in case
>    // such construction creates the DIE.
>    auto *Context = resolve(Ty->getScope());
> -  if (ContextDIE == nullptr)
> -    ContextDIE = getOrCreateContextDIE(Context);
> +  DIE *ContextDIE = getOrCreateContextDIE(Context);
> +  assert(ContextDIE);
>
>    if (DIE *TyDIE = getDIE(Ty))
>      return TyDIE;
>
> -  assert(ContextDIE);
> -
>    // Create new type.
>    DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
>
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h?rev=241176&r1=241175&r2=241176&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.h Wed Jul  1 13:07:16 2015
> @@ -298,9 +298,7 @@ public:
>                                   bool Minimal = false);
>
>    /// \brief Find existing DIE or create new DIE for the given type.
> -  /// \param N Type Node
> -  /// \param ContextDIE DIE scope for N Node, if available.
> -  DIE *getOrCreateTypeDIE(const MDNode *N, DIE *ContextDIE = nullptr);
> +  DIE *getOrCreateTypeDIE(const MDNode *N);
>
>    /// \brief Get context owner's DIE.
>    DIE *createTypeDIE(const DICompositeType *Ty);
>
> Removed: llvm/trunk/test/DebugInfo/X86/lexical-block-pr19238.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/lexical-block-pr19238.ll?rev=241175&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/lexical-block-pr19238.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/lexical-block-pr19238.ll (removed)
> @@ -1,129 +0,0 @@
> -; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj -O0 < %s  |
> llvm-dwarfdump -debug-dump=info - | FileCheck %s
> -
> -;; This test checks the following:
> -;; 1. Useless lexical block entry is not emitted
> -;; 2. Function static variable, typedef, records (structure, class and
> union)
> -;;    that are defined in lexical basic block are emitted as children to
> -;;    these lexical blocks.
> -;;    * For typedef and record check that both are emitted in lexical
> block
> -;;      where they are declared and not in the one where they are used.
> -;;
> -;; This test was generated by running following command:
> -;; clang -cc1 -O0 -g -emit-llvm foo.cpp
> -;; Where foo.cpp
> -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> -;;int foo(void) {
> -;;  {
> -;;    {
> -;;      struct X {
> -;;        int x;
> -;;      };
> -;;      typedef int Y;
> -;;      {
> -;;        X a;
> -;;        Y b;
> -;;        static int c;
> -;;        return a.x + b + c;
> -;;      }
> -;;    }
> -;;  }
> -;;}
> -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> -
> -
> -; CHECK:      DW_TAG_subprogram
> -; CHECK-NOT: DW_TAG
> -; CHECK:        DW_AT_name {{.*}} "foo"
> -; CHECK-NOT: NULL
> -; CHECK:      DW_TAG_lexical_block
> -
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:        DW_TAG_structure_type
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:          DW_AT_name {{.*}} "X"
> -; CHECK:          NULL
> -
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:        DW_TAG_typedef
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:          DW_AT_name {{.*}} "Y"
> -
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:        DW_TAG_lexical_block
> -
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:        DW_TAG_variable
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:          DW_AT_name {{.*}} "c"
> -
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:        DW_TAG_variable
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:          DW_AT_name {{.*}} "a"
> -
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:        DW_TAG_variable
> -; CHECK-NOT: {{DW_TAG|NULL}}
> -; CHECK:          DW_AT_name {{.*}} "b"
> -
> -; CHECK-NOT: {{DW_TAG}}
> -; CHECK:        NULL
> -
> -
> -%struct.X = type { i32 }
> -
> - at _ZZ3foovE1c = internal global i32 0, align 4
> -
> -; Function Attrs: nounwind
> -define i32 @_Z3foov() #0 {
> -entry:
> -  %a = alloca %struct.X, align 4
> -  %b = alloca i32, align 4
> -  call void @llvm.dbg.declare(metadata %struct.X* %a, metadata !21,
> metadata !22), !dbg !23
> -  call void @llvm.dbg.declare(metadata i32* %b, metadata !24, metadata
> !22), !dbg !25
> -  %x = getelementptr inbounds %struct.X, %struct.X* %a, i32 0, i32 0,
> !dbg !26
> -  %0 = load i32, i32* %x, align 4, !dbg !26
> -  %1 = load i32, i32* %b, align 4, !dbg !26
> -  %add = add nsw i32 %0, %1, !dbg !26
> -  %2 = load i32, i32* @_ZZ3foovE1c, align 4, !dbg !26
> -  %add1 = add nsw i32 %add, %2, !dbg !26
> -  ret i32 %add1, !dbg !26
> -}
> -
> -; Function Attrs: nounwind readnone
> -declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
> -
> -attributes #0 = { nounwind "less-precise-fpmad"="false"
> "no-frame-pointer-elim"="false" "no-infs-fp-math"="false"
> "no-nans-fp-math"="false" "no-realign-stack"
> "stack-protector-buffer-size"="8" "target-features"="+sse,+sse2"
> "unsafe-fp-math"="false" "use-soft-float"="false" }
> -attributes #1 = { nounwind readnone }
> -
> -!llvm.dbg.cu = !{!0}
> -!llvm.module.flags = !{!18, !19}
> -!llvm.ident = !{!20}
> -
> -!0 = !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer:
> "clang version 3.7.0 (trunk 237245)", isOptimized: false, runtimeVersion:
> 0, emissionKind: 1, enums: !2, retainedTypes: !3, subprograms: !14,
> globals: !15, imports: !2)
> -!1 = !DIFile(filename: "foo.cpp", directory: "/")
> -!2 = !{}
> -!3 = !{!4, !13}
> -!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: !5,
> file: !1, line: 4, size: 32, align: 32, elements: !11)
> -!5 = distinct !DILexicalBlock(scope: !6, file: !1, line: 3)
> -!6 = distinct !DILexicalBlock(scope: !7, file: !1, line: 2)
> -!7 = !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file:
> !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1,
> flags: DIFlagPrototyped, isOptimized: false, function: i32 ()* @_Z3foov,
> variables: !2)
> -!8 = !DISubroutineType(types: !9)
> -!9 = !{!10}
> -!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding:
> DW_ATE_signed)
> -!11 = !{!12}
> -!12 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !4, file: !1,
> line: 5, baseType: !10, size: 32, align: 32)
> -!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: !5, file: !1,
> line: 7, baseType: !10)
> -!14 = !{!7}
> -!15 = !{!16}
> -!16 = !DIGlobalVariable(name: "c", scope: !17, file: !1, line: 11, type:
> !10, isLocal: true, isDefinition: true, variable: i32* @_ZZ3foovE1c)
> -!17 = distinct !DILexicalBlock(scope: !5, file: !1, line: 8)
> -!18 = !{i32 2, !"Dwarf Version", i32 4}
> -!19 = !{i32 2, !"Debug Info Version", i32 3}
> -!20 = !{!"clang version 3.7.0 (trunk 237245)"}
> -!21 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "a", scope: !17,
> file: !1, line: 9, type: !4)
> -!22 = !DIExpression()
> -!23 = !DILocation(line: 9, scope: !17)
> -!24 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "b", scope: !17,
> file: !1, line: 10, type: !13)
> -!25 = !DILocation(line: 10, scope: !17)
> -!26 = !DILocation(line: 12, scope: !17)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150701/b010471a/attachment.html>


More information about the llvm-commits mailing list