llvm.org GIT mirror llvm / b99e0eb
Revert "[DWARF] Fix debug info generation for function static variables, typedefs, and records" Caused PR24008 This reverts commit 37cb5f1c2db9f42d29f26b215585f56bb64ae4f5. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241176 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 5 years ago
8 changed file(s) with 35 addition(s) and 194 deletion(s). Raw diff Collapse all Expand all
5252 }
5353 }
5454
55 template
56 bool empty(const R& r) { return begin(r) == end(r); }
57
5855 #endif
100100
101101 /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
102102 DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
103 const DIGlobalVariable *GV, DIE *ContextDIE) {
103 const DIGlobalVariable *GV) {
104104 // Check for pre-existence.
105105 if (DIE *Die = getDIE(GV))
106106 return Die;
112112
113113 // Construct the context before querying for the existence of the DIE in
114114 // case such construction creates the DIE.
115 if (ContextDIE == nullptr)
116 ContextDIE = getOrCreateContextDIE(GVContext);
115 DIE *ContextDIE = getOrCreateContextDIE(GVContext);
117116
118117 // Add to map.
119118 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
335334 // null and the children will be added to the scope DIE.
336335 createScopeChildrenDIE(Scope, Children, &ChildScopeCount);
337336
338
339 DwarfDebug::LocalDeclMapRange LocalDeclNodeRangeForScope(nullptr, nullptr);
340 // Skip local decls in gmlt-like data.
341 if (!includeMinimalInlineScopes())
342 LocalDeclNodeRangeForScope = DD->findLocalDeclNodesForScope(DS);
337 // Skip imported directives in gmlt-like data.
338 if (!includeMinimalInlineScopes()) {
339 // There is no need to emit empty lexical block DIE.
340 for (const auto &E : DD->findImportedEntitiesForScope(DS))
341 Children.push_back(
342 constructImportedEntityDIE(cast(E.second)));
343 }
343344
344345 // If there are only other scopes as children, put them directly in the
345346 // parent instead, as this scope would serve no purpose.
346 if (Children.size() == ChildScopeCount &&
347 empty(LocalDeclNodeRangeForScope)) {
347 if (Children.size() == ChildScopeCount) {
348348 FinalChildren.insert(FinalChildren.end(),
349349 std::make_move_iterator(Children.begin()),
350350 std::make_move_iterator(Children.end()));
352352 }
353353 ScopeDIE = constructLexicalScopeDIE(Scope);
354354 assert(ScopeDIE && "Scope DIE should not be null.");
355
356 for (const auto &DI : LocalDeclNodeRangeForScope) {
357 if (auto *IE = dyn_cast(DI.second))
358 Children.push_back(constructImportedEntityDIE(IE));
359 else if (auto *GV = dyn_cast(DI.second))
360 getOrCreateGlobalVariableDIE(GV, ScopeDIE);
361 else if (auto *RT = dyn_cast(DI.second))
362 getOrCreateTypeDIE(RT, ScopeDIE);
363 }
364355 }
365356
366357 // Add children
7676 /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
7777 void applyStmtList(DIE &D);
7878
79 /// Get or create global variable DIE.
80 /// \param GV Global Variable Node
81 /// \param ContextDIE DIE scope for GV Node, if available.
82 DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV,
83 DIE *ContextDIE = nullptr);
79 /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
80 DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV);
8481
8582 /// addLabelAddress - Add a dwarf label attribute data and value using
8683 /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
448448 auto *CUNode = cast(N);
449449 DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
450450 for (auto *IE : CUNode->getImportedEntities())
451 ScopesWithLocalDeclNodes.push_back(std::make_pair(IE->getScope(), IE));
452 for (auto *GV : CUNode->getGlobalVariables()) {
453 auto *Context = GV->getScope();
454 if (Context && isa(Context))
455 ScopesWithLocalDeclNodes.push_back(std::make_pair(Context, GV));
456 else
457 CU.getOrCreateGlobalVariableDIE(GV);
458 }
451 ScopesWithImportedEntities.push_back(std::make_pair(IE->getScope(), IE));
452 // Stable sort to preserve the order of appearance of imported entities.
453 // This is to avoid out-of-order processing of interdependent declarations
454 // within the same scope, e.g. { namespace A = base; namespace B = A; }
455 std::stable_sort(ScopesWithImportedEntities.begin(),
456 ScopesWithImportedEntities.end(), less_first());
457 for (auto *GV : CUNode->getGlobalVariables())
458 CU.getOrCreateGlobalVariableDIE(GV);
459459 for (auto *SP : CUNode->getSubprograms())
460460 SPMap.insert(std::make_pair(SP, &CU));
461461 for (auto *Ty : CUNode->getEnumTypes()) {
466466 for (auto *Ty : CUNode->getRetainedTypes()) {
467467 // The retained types array by design contains pointers to
468468 // MDNodes rather than DIRefs. Unique them here.
469 DIType *RT = cast(resolve(Ty->getRef()));
470 auto *Context = resolve(Ty->getScope());
471 if (Context && isa(Context))
472 ScopesWithLocalDeclNodes.push_back(std::make_pair(Context, RT));
473 else
474 CU.getOrCreateTypeDIE(RT);
469 CU.getOrCreateTypeDIE(cast(resolve(Ty->getRef())));
475470 }
476471 // Emit imported_modules last so that the relevant context is already
477472 // available.
478473 for (auto *IE : CUNode->getImportedEntities())
479474 constructAndAddImportedEntityDIE(CU, IE);
480
481 // Stable sort to preserve the order of appearance of imported entities.
482 // This is to avoid out-of-order processing of interdependent declarations
483 // within the same scope, e.g. { namespace A = base; namespace B = A; }
484 std::stable_sort(ScopesWithLocalDeclNodes.begin(),
485 ScopesWithLocalDeclNodes.end(), less_first());
486475 }
487476
488477 // Tell MMI that we have debug info.
277277 // Holder for the file specific debug information.
278278 DwarfFile InfoHolder;
279279
280 // Holder for local declaration DI nodes per scope.
280 // Holders for the various debug information flags that we might need to
281 // have exposed. See accessor functions below for description.
282
283 // Holder for imported entities.
281284 typedef SmallVector, 32>
282 LocalDeclMap;
283 LocalDeclMap ScopesWithLocalDeclNodes;
285 ImportedEntityMap;
286 ImportedEntityMap ScopesWithImportedEntities;
284287
285288 // Map from MDNodes for user-defined types to the type units that describe
286289 // them.
615618
616619 const MachineFunction *getCurrentFunction() const { return CurFn; }
617620
618 typedef iterator_range LocalDeclMapRange;
619
620 LocalDeclMapRange findLocalDeclNodesForScope(const MDNode *Scope) const {
621 assert(DILexicalBlockBase::classof(Scope) && "Expected LexicalBlock scope");
621 iterator_range
622 findImportedEntitiesForScope(const MDNode *Scope) const {
622623 return make_range(std::equal_range(
623 ScopesWithLocalDeclNodes.begin(), ScopesWithLocalDeclNodes.end(),
624 ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
624625 std::pair(Scope, nullptr),
625626 less_first()));
626627 }
703703 return &TyDIE;
704704 }
705705
706 DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode, DIE *ContextDIE) {
706 DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
707707 if (!TyNode)
708708 return nullptr;
709709
713713
714714 // DW_TAG_restrict_type is not supported in DWARF2
715715 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
716 return getOrCreateTypeDIE(resolve(cast(Ty)->getBaseType()),
717 ContextDIE);
716 return getOrCreateTypeDIE(resolve(cast(Ty)->getBaseType()));
718717
719718 // Construct the context before querying for the existence of the DIE in case
720719 // such construction creates the DIE.
721720 auto *Context = resolve(Ty->getScope());
722 if (ContextDIE == nullptr)
723 ContextDIE = getOrCreateContextDIE(Context);
721 DIE *ContextDIE = getOrCreateContextDIE(Context);
722 assert(ContextDIE);
724723
725724 if (DIE *TyDIE = getDIE(Ty))
726725 return TyDIE;
727
728 assert(ContextDIE);
729726
730727 // Create new type.
731728 DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
297297 bool Minimal = false);
298298
299299 /// \brief Find existing DIE or create new DIE for the given type.
300 /// \param N Type Node
301 /// \param ContextDIE DIE scope for N Node, if available.
302 DIE *getOrCreateTypeDIE(const MDNode *N, DIE *ContextDIE = nullptr);
300 DIE *getOrCreateTypeDIE(const MDNode *N);
303301
304302 /// \brief Get context owner's DIE.
305303 DIE *createTypeDIE(const DICompositeType *Ty);
+0
-129
test/DebugInfo/X86/lexical-block-pr19238.ll less more
None ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj -O0 < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
1
2 ;; This test checks the following:
3 ;; 1. Useless lexical block entry is not emitted
4 ;; 2. Function static variable, typedef, records (structure, class and union)
5 ;; that are defined in lexical basic block are emitted as children to
6 ;; these lexical blocks.
7 ;; * For typedef and record check that both are emitted in lexical block
8 ;; where they are declared and not in the one where they are used.
9 ;;
10 ;; This test was generated by running following command:
11 ;; clang -cc1 -O0 -g -emit-llvm foo.cpp
12 ;; Where foo.cpp
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14 ;;int foo(void) {
15 ;; {
16 ;; {
17 ;; struct X {
18 ;; int x;
19 ;; };
20 ;; typedef int Y;
21 ;; {
22 ;; X a;
23 ;; Y b;
24 ;; static int c;
25 ;; return a.x + b + c;
26 ;; }
27 ;; }
28 ;; }
29 ;;}
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31
32
33 ; CHECK: DW_TAG_subprogram
34 ; CHECK-NOT: DW_TAG
35 ; CHECK: DW_AT_name {{.*}} "foo"
36 ; CHECK-NOT: NULL
37 ; CHECK: DW_TAG_lexical_block
38
39 ; CHECK-NOT: {{DW_TAG|NULL}}
40 ; CHECK: DW_TAG_structure_type
41 ; CHECK-NOT: {{DW_TAG|NULL}}
42 ; CHECK: DW_AT_name {{.*}} "X"
43 ; CHECK: NULL
44
45 ; CHECK-NOT: {{DW_TAG|NULL}}
46 ; CHECK: DW_TAG_typedef
47 ; CHECK-NOT: {{DW_TAG|NULL}}
48 ; CHECK: DW_AT_name {{.*}} "Y"
49
50 ; CHECK-NOT: {{DW_TAG|NULL}}
51 ; CHECK: DW_TAG_lexical_block
52
53 ; CHECK-NOT: {{DW_TAG|NULL}}
54 ; CHECK: DW_TAG_variable
55 ; CHECK-NOT: {{DW_TAG|NULL}}
56 ; CHECK: DW_AT_name {{.*}} "c"
57
58 ; CHECK-NOT: {{DW_TAG|NULL}}
59 ; CHECK: DW_TAG_variable
60 ; CHECK-NOT: {{DW_TAG|NULL}}
61 ; CHECK: DW_AT_name {{.*}} "a"
62
63 ; CHECK-NOT: {{DW_TAG|NULL}}
64 ; CHECK: DW_TAG_variable
65 ; CHECK-NOT: {{DW_TAG|NULL}}
66 ; CHECK: DW_AT_name {{.*}} "b"
67
68 ; CHECK-NOT: {{DW_TAG}}
69 ; CHECK: NULL
70
71
72 %struct.X = type { i32 }
73
74 @_ZZ3foovE1c = internal global i32 0, align 4
75
76 ; Function Attrs: nounwind
77 define i32 @_Z3foov() #0 {
78 entry:
79 %a = alloca %struct.X, align 4
80 %b = alloca i32, align 4
81 call void @llvm.dbg.declare(metadata %struct.X* %a, metadata !21, metadata !22), !dbg !23
82 call void @llvm.dbg.declare(metadata i32* %b, metadata !24, metadata !22), !dbg !25
83 %x = getelementptr inbounds %struct.X, %struct.X* %a, i32 0, i32 0, !dbg !26
84 %0 = load i32, i32* %x, align 4, !dbg !26
85 %1 = load i32, i32* %b, align 4, !dbg !26
86 %add = add nsw i32 %0, %1, !dbg !26
87 %2 = load i32, i32* @_ZZ3foovE1c, align 4, !dbg !26
88 %add1 = add nsw i32 %add, %2, !dbg !26
89 ret i32 %add1, !dbg !26
90 }
91
92 ; Function Attrs: nounwind readnone
93 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
94
95 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" }
96 attributes #1 = { nounwind readnone }
97
98 !llvm.dbg.cu = !{!0}
99 !llvm.module.flags = !{!18, !19}
100 !llvm.ident = !{!20}
101
102 !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)
103 !1 = !DIFile(filename: "foo.cpp", directory: "/")
104 !2 = !{}
105 !3 = !{!4, !13}
106 !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: !5, file: !1, line: 4, size: 32, align: 32, elements: !11)
107 !5 = distinct !DILexicalBlock(scope: !6, file: !1, line: 3)
108 !6 = distinct !DILexicalBlock(scope: !7, file: !1, line: 2)
109 !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)
110 !8 = !DISubroutineType(types: !9)
111 !9 = !{!10}
112 !10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
113 !11 = !{!12}
114 !12 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !4, file: !1, line: 5, baseType: !10, size: 32, align: 32)
115 !13 = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: !5, file: !1, line: 7, baseType: !10)
116 !14 = !{!7}
117 !15 = !{!16}
118 !16 = !DIGlobalVariable(name: "c", scope: !17, file: !1, line: 11, type: !10, isLocal: true, isDefinition: true, variable: i32* @_ZZ3foovE1c)
119 !17 = distinct !DILexicalBlock(scope: !5, file: !1, line: 8)
120 !18 = !{i32 2, !"Dwarf Version", i32 4}
121 !19 = !{i32 2, !"Debug Info Version", i32 3}
122 !20 = !{!"clang version 3.7.0 (trunk 237245)"}
123 !21 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "a", scope: !17, file: !1, line: 9, type: !4)
124 !22 = !DIExpression()
125 !23 = !DILocation(line: 9, scope: !17)
126 !24 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "b", scope: !17, file: !1, line: 10, type: !13)
127 !25 = !DILocation(line: 10, scope: !17)
128 !26 = !DILocation(line: 12, scope: !17)