llvm.org GIT mirror llvm / 91a7b5a
Merging r318289: ------------------------------------------------------------------------ r318289 | jdevlieghere | 2017-11-15 02:57:05 -0800 (Wed, 15 Nov 2017) | 14 lines [DebugInfo] Fix potential CU mismatch for SubprogramScopeDIEs. In constructAbstractSubprogramScopeDIE there can be a potential mismatch between `this` and the CU of ContextDIE when a scope is shared between two DISubprograms belonging to a different CU. In that case, `this` is the CU that was specified in the IR, but the CU of ContextDIE is that of the first subprogram that was emitted. This patch fixes the mismatch by looking up the CU of ContextDIE, and switching to use that. This fixes PR35212 (https://bugs.llvm.org/show_bug.cgi?id=35212) Patch by Philip Craig! Differential revision: https://reviews.llvm.org/D39981 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@318542 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 1 year, 9 months ago
3 changed file(s) with 68 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
620620 auto *SP = cast(Scope->getScopeNode());
621621
622622 DIE *ContextDIE;
623 DwarfCompileUnit *ContextCU = this;
623624
624625 if (includeMinimalInlineScopes())
625626 ContextDIE = &getUnitDie();
630631 else if (auto *SPDecl = SP->getDeclaration()) {
631632 ContextDIE = &getUnitDie();
632633 getOrCreateSubprogramDIE(SPDecl);
633 } else
634 } else {
634635 ContextDIE = getOrCreateContextDIE(resolve(SP->getScope()));
636 // The scope may be shared with a subprogram that has already been
637 // constructed in another CU, in which case we need to construct this
638 // subprogram in the same CU.
639 ContextCU = DD->lookupCU(ContextDIE->getUnitDie());
640 }
635641
636642 // Passing null as the associated node because the abstract definition
637643 // shouldn't be found by lookup.
638 AbsDef = &createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr);
639 applySubprogramAttributesToDefinition(SP, *AbsDef);
640
641 if (!includeMinimalInlineScopes())
642 addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
643 if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, *AbsDef))
644 addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
644 AbsDef = &ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr);
645 ContextCU->applySubprogramAttributesToDefinition(SP, *AbsDef);
646
647 if (!ContextCU->includeMinimalInlineScopes())
648 ContextCU->addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
649 if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, *AbsDef))
650 ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
645651 }
646652
647653 DIE *DwarfCompileUnit::constructImportedEntityDIE(
282282 // 0, referencing the comp_dir of all the type units that use it.
283283 MCDwarfDwoLineTable SplitTypeUnitFileTable;
284284 /// @}
285
285
286286 /// True iff there are multiple CUs in this module.
287287 bool SingleCU;
288288 bool IsDarwin;
561561 bool isLexicalScopeDIENull(LexicalScope *Scope);
562562
563563 bool hasDwarfPubSections(bool includeMinimalInlineScopes) const;
564
565 /// Find the matching DwarfCompileUnit for the given CU DIE.
566 DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); }
564567 };
565568 } // End of namespace llvm
566569
0 ; RUN: %llc_dwarf %s -filetype=obj -o %t
1 ; RUN: llvm-dwarfdump -debug-dump=info %t | FileCheck %s
2
3 ; Reduced test case from PR35212. Two DISubprogram belong to a different CU but
4 ; share a scope. Both are declarations and end up in the scope's CU. We want to
5 ; check that the CU from the context DIE is used (rather than from the IR).
6 ; This manifests itself by the DW_base_type ending up in the second CU, rather
7 ; than in the first one as specified in the IR.
8
9 ; CHECK: DW_TAG_compile_unit
10 ; CHECK-NEXT: discriminator 0
11 ; CHECK: DW_TAG_compile_unit
12 ; CHECK-NEXT: discriminator 1
13 ; CHECK: DW_TAG_structure_type
14 ; CHECK-NOT: NULL
15 ; CHECK: DW_TAG_subprogram
16 ; CHECK-NOT: NULL
17 ; CHECK: DW_TAG_formal_parameter
18 ; CHECK-NOT: NULL
19 ; CHECK: DW_AT_type{{.*}}{[[USIZE_LABEL:0x[0-9a-f]+]]}
20 ; CHECK: NULL
21 ; CHECK: [[USIZE_LABEL]]: DW_TAG_base_type
22 ; CHECK-NOT: NULL
23 ; CHECK: DW_AT_name{{.*}}"usize"
24
25 define hidden void @foo() !dbg !4 {
26 ret void, !dbg !7
27 }
28
29 !llvm.dbg.cu = !{!0, !2}
30 !llvm.module.flags = !{!3}
31
32 !0 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1, producer: "clang LLVM (rustc version 1.23.0-nightly (discriminator 0))", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
33 !1 = !DIFile(filename: "../lib.rs", directory: "/home/alex/code/rust4/lol")
34 !2 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1, producer: "clang LLVM (rustc version 1.23.0-nightly (discriminator 1))", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
35 !3 = !{i32 2, !"Debug Info Version", i32 3}
36 !4 = distinct !DISubprogram(name: "clone", linkageName: "_ZN5alloc3vec8{{impl}}28cloneE", scope: null, file: !1, line: 1519, type: !5, isLocal: false, isDefinition: true, scopeLine: 1519, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !6, variables: !6)
37 !5 = !DISubroutineType(types: !6)
38 !6 = !{}
39 !7 = !DILocation(line: 1612, scope: !8, inlinedAt: !11)
40 !8 = distinct !DILexicalBlock(scope: !9, file: !1, line: 86, column: 12)
41 !9 = distinct !DISubprogram(name: "allocate_in", linkageName: "_ZN5alloc7raw_vec8{{impl}}52allocate_inE", scope: !10, file: !1, line: 82, type: !5, isLocal: false, isDefinition: true, scopeLine: 82, flags: DIFlagPrototyped, isOptimized: true, unit: !2, templateParams: !6, variables: !6)
42 !10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "RawVec", file: !1, size: 128, align: 64, elements: !6, identifier: "5c6e4db16d2c64555e40661d70c4d81e")
43 !11 = distinct !DILocation(line: 86, scope: !8, inlinedAt: !12)
44 !12 = distinct !DILocation(line: 141, scope: !13, inlinedAt: !17)
45 !13 = distinct !DISubprogram(name: "with_capacity", linkageName: "_ZN5alloc7raw_vec8{{impl}}36with_capacityE", scope: !10, file: !1, line: 140, type: !5, isLocal: false, isDefinition: true, scopeLine: 140, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !6, variables: !14)
46 !14 = !{!15}
47 !15 = !DILocalVariable(name: "cap", arg: 1, scope: !13, file: !1, line: 1, type: !16)
48 !16 = !DIBasicType(name: "usize", size: 64, encoding: DW_ATE_unsigned)
49 !17 = !DILocation(line: 1521, scope: !4)