llvm.org GIT mirror llvm / e521278
Recommit, with fixes: Add some support for dealing with an object pointer on arguments. Part of rdar://9797999 which now supports adding the object pointer attribute to the subprogram as it should. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163754 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 7 years ago
7 changed file(s) with 140 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
345345
346346 /// createArtificialType - Create a new DIType with "artificial" flag set.
347347 DIType createArtificialType(DIType Ty);
348
349 /// createObjectPointerType - Create a new DIType with the "object pointer"
350 /// flag set.
351 DIType createObjectPointerType(DIType Ty);
348352
349353 /// createTemporaryType - Create a temporary forward-declared type.
350354 DIType createTemporaryType();
5959 FlagArtificial = 1 << 6,
6060 FlagExplicit = 1 << 7,
6161 FlagPrototyped = 1 << 8,
62 FlagObjcClassComplete = 1 << 9
62 FlagObjcClassComplete = 1 << 9,
63 FlagObjectPointer = 1 << 10
6364 };
6465 protected:
6566 const MDNode *DbgNode;
286287 bool isArtificial() const {
287288 return (getFlags() & FlagArtificial) != 0;
288289 }
290 bool isObjectPointer() const {
291 return (getFlags() & FlagObjectPointer) != 0;
292 }
289293 bool isObjcClassComplete() const {
290294 return (getFlags() & FlagObjcClassComplete) != 0;
291295 }
643647 return (getUnsignedField(6) & FlagArtificial) != 0;
644648 }
645649
650 bool isObjectPointer() const {
651 return (getUnsignedField(6) & FlagObjectPointer) != 0;
652 }
653
646654 /// getInlinedAt - If this variable is inlined then return inline location.
647655 MDNode *getInlinedAt() const;
648656
11081108 addType(Arg, ATy);
11091109 if (ATy.isArtificial())
11101110 addFlag(Arg, dwarf::DW_AT_artificial);
1111 if (ATy.isObjectPointer())
1112 addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4,
1113 Arg);
11111114 SPDie->addChild(Arg);
11121115 }
11131116 }
329329 SPCU->addType(Arg, ATy);
330330 if (ATy.isArtificial())
331331 SPCU->addFlag(Arg, dwarf::DW_AT_artificial);
332 if (ATy.isObjectPointer())
333 SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, dwarf::DW_FORM_ref4,
334 Arg);
332335 SPDie->addChild(Arg);
333336 }
334337 DIE *SPDeclDie = SPDie;
495498 return NULL;
496499
497500 SmallVector Children;
501 DIE *ObjectPointer = NULL;
498502
499503 // Collect arguments for current function.
500504 if (LScopes.isCurrentFunctionScope(Scope))
501505 for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i)
502506 if (DbgVariable *ArgDV = CurrentFnArguments[i])
503507 if (DIE *Arg =
504 TheCU->constructVariableDIE(ArgDV, Scope->isAbstractScope()))
508 TheCU->constructVariableDIE(ArgDV, Scope->isAbstractScope())) {
505509 Children.push_back(Arg);
510 if (ArgDV->isObjectPointer()) ObjectPointer = Arg;
511 }
506512
507513 // Collect lexical scope children first.
508514 const SmallVector &Variables = ScopeVariables.lookup(Scope);
542548 for (SmallVector::iterator I = Children.begin(),
543549 E = Children.end(); I != E; ++I)
544550 ScopeDIE->addChild(*I);
551
552 if (DS.isSubprogram() && ObjectPointer != NULL)
553 TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer,
554 dwarf::DW_FORM_ref4, ObjectPointer);
545555
546556 if (DS.isSubprogram())
547557 TheCU->addPubTypes(DISubprogram(DS));
163163 return true;
164164 return false;
165165 }
166
167 bool isObjectPointer() const {
168 if (Var.isObjectPointer())
169 return true;
170 if (Var.getTag() == dwarf::DW_TAG_arg_variable
171 && getType().isObjectPointer())
172 return true;
173 return false;
174 }
175
166176 bool variableHasComplexAddress() const {
167177 assert(Var.Verify() && "Invalid complex DbgVariable!");
168178 return Var.hasComplexAddress();
635635
636636 // Flags are stored at this slot.
637637 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
638
639 return DIType(MDNode::get(VMContext, Elts));
640 }
641
642 /// createArtificialType - Create a new DIType with "artificial" flag set.
643 DIType DIBuilder::createObjectPointerType(DIType Ty) {
644 if (Ty.isObjectPointer())
645 return Ty;
646
647 SmallVector Elts;
648 MDNode *N = Ty;
649 assert (N && "Unexpected input DIType!");
650 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
651 if (Value *V = N->getOperand(i))
652 Elts.push_back(V);
653 else
654 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
655 }
656
657 unsigned CurFlags = Ty.getFlags();
658 CurFlags = CurFlags | (DIType::FlagObjectPointer | DIType::FlagArtificial);
659
660 // Flags are stored at this slot.
661 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
638662
639663 return DIType(MDNode::get(VMContext, Elts));
640664 }
0 ; RUN: llc -mtriple=x86_64-apple-darwin %s -o %t -filetype=obj
1 ; RUN: llvm-dwarfdump %t | FileCheck %s
2
3 ; CHECK: DW_AT_object_pointer [DW_FORM_ref4] (cu + 0x00c3 => {0x000000c3})
4 ; CHECK: 0x000000c3: DW_TAG_formal_parameter [12]
5 ; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000085] = "this")
6
7 %class.A = type { i32 }
8
9 define i32 @_Z3foov() nounwind uwtable ssp {
10 entry:
11 %a = alloca %class.A, align 4
12 call void @llvm.dbg.declare(metadata !{%class.A* %a}, metadata !21), !dbg !23
13 call void @_ZN1AC1Ev(%class.A* %a), !dbg !24
14 %m_a = getelementptr inbounds %class.A* %a, i32 0, i32 0, !dbg !25
15 %0 = load i32* %m_a, align 4, !dbg !25
16 ret i32 %0, !dbg !25
17 }
18
19 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
20
21 define linkonce_odr void @_ZN1AC1Ev(%class.A* %this) unnamed_addr nounwind uwtable ssp align 2 {
22 entry:
23 %this.addr = alloca %class.A*, align 8
24 store %class.A* %this, %class.A** %this.addr, align 8
25 call void @llvm.dbg.declare(metadata !{%class.A** %this.addr}, metadata !26), !dbg !28
26 %this1 = load %class.A** %this.addr
27 call void @_ZN1AC2Ev(%class.A* %this1), !dbg !29
28 ret void, !dbg !29
29 }
30
31 define linkonce_odr void @_ZN1AC2Ev(%class.A* %this) unnamed_addr nounwind uwtable ssp align 2 {
32 entry:
33 %this.addr = alloca %class.A*, align 8
34 store %class.A* %this, %class.A** %this.addr, align 8
35 call void @llvm.dbg.declare(metadata !{%class.A** %this.addr}, metadata !30), !dbg !31
36 %this1 = load %class.A** %this.addr
37 %m_a = getelementptr inbounds %class.A* %this1, i32 0, i32 0, !dbg !32
38 store i32 0, i32* %m_a, align 4, !dbg !32
39 ret void, !dbg !34
40 }
41
42 !llvm.dbg.cu = !{!0}
43
44 !0 = metadata !{i32 786449, i32 0, i32 4, metadata !"bar.cpp", metadata !"/Users/echristo/debug-tests", metadata !"clang version 3.2 (trunk 163586) (llvm/trunk 163570)", i1 true, i1 false, metadata !"", i32 0, metadata !1, metadata !1, metadata !3, metadata !1} ; [ DW_TAG_compile_unit ] [/Users/echristo/debug-tests/bar.cpp] [DW_LANG_C_plus_plus]
45 !1 = metadata !{metadata !2}
46 !2 = metadata !{i32 0}
47 !3 = metadata !{metadata !4}
48 !4 = metadata !{metadata !5, metadata !10, metadata !20}
49 !5 = metadata !{i32 786478, i32 0, metadata !6, metadata !"foo", metadata !"foo", metadata !"_Z3foov", metadata !6, i32 7, metadata !7, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @_Z3foov, null, null, metadata !1, i32 7} ; [ DW_TAG_subprogram ] [line 7] [def] [foo]
50 !6 = metadata !{i32 786473, metadata !"bar.cpp", metadata !"/Users/echristo/debug-tests", null} ; [ DW_TAG_file_type ]
51 !7 = metadata !{i32 786453, i32 0, metadata !"", i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !8, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
52 !8 = metadata !{metadata !9}
53 !9 = metadata !{i32 786468, null, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
54 !10 = metadata !{i32 786478, i32 0, null, metadata !"A", metadata !"A", metadata !"_ZN1AC1Ev", metadata !6, i32 3, metadata !11, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (%class.A*)* @_ZN1AC1Ev, null, metadata !17, metadata !1, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [A]
55 !11 = metadata !{i32 786453, i32 0, metadata !"", i32 0, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !12, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
56 !12 = metadata !{null, metadata !13}
57 !13 = metadata !{i32 786447, i32 0, metadata !"", i32 0, i32 0, i64 64, i64 64, i64 0, i32 1088, metadata !14} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from A]
58 !14 = metadata !{i32 786434, null, metadata !"A", metadata !6, i32 1, i64 32, i64 32, i32 0, i32 0, null, metadata !15, i32 0, null, null} ; [ DW_TAG_class_type ] [A] [line 1, size 32, align 32, offset 0] [from ]
59 !15 = metadata !{metadata !16, metadata !17}
60 !16 = metadata !{i32 786445, metadata !14, metadata !"m_a", metadata !6, i32 4, i64 32, i64 32, i64 0, i32 0, metadata !9} ; [ DW_TAG_member ] [m_a] [line 4, size 32, align 32, offset 0] [from int]
61 !17 = metadata !{i32 786478, i32 0, metadata !14, metadata !"A", metadata !"A", metadata !"", metadata !6, i32 3, metadata !11, i1 false, i1 false, i32 0, i32 0, null, i32 256, i1 false, null, null, i32 0, metadata !18, i32 3} ; [ DW_TAG_subprogram ] [line 3] [A]
62 !18 = metadata !{metadata !19}
63 !19 = metadata !{i32 786468} ; [ DW_TAG_base_type ] [line 0, size 0, align 0, offset 0]
64 !20 = metadata !{i32 786478, i32 0, null, metadata !"A", metadata !"A", metadata !"_ZN1AC2Ev", metadata !6, i32 3, metadata !11, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, void (%class.A*)* @_ZN1AC2Ev, null, metadata !17, metadata !1, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [A]
65 !21 = metadata !{i32 786688, metadata !22, metadata !"a", metadata !6, i32 8, metadata !14, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [a] [line 8]
66 !22 = metadata !{i32 786443, metadata !5, i32 7, i32 11, metadata !6, i32 0} ; [ DW_TAG_lexical_block ] [/Users/echristo/debug-tests/bar.cpp]
67 !23 = metadata !{i32 8, i32 5, metadata !22, null}
68 !24 = metadata !{i32 8, i32 6, metadata !22, null}
69 !25 = metadata !{i32 9, i32 3, metadata !22, null}
70 !26 = metadata !{i32 786689, metadata !10, metadata !"this", metadata !6, i32 16777219, metadata !27, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 3]
71 !27 = metadata !{i32 786447, null, metadata !"", null, i32 0, i64 64, i64 64, i64 0, i32 0, metadata !14} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from A]
72 !28 = metadata !{i32 3, i32 3, metadata !10, null}
73 !29 = metadata !{i32 3, i32 18, metadata !10, null}
74 !30 = metadata !{i32 786689, metadata !20, metadata !"this", metadata !6, i32 16777219, metadata !27, i32 1088, i32 0} ; [ DW_TAG_arg_variable ] [this] [line 3]
75 !31 = metadata !{i32 3, i32 3, metadata !20, null}
76 !32 = metadata !{i32 3, i32 9, metadata !33, null}
77 !33 = metadata !{i32 786443, metadata !20, i32 3, i32 7, metadata !6, i32 1} ; [ DW_TAG_lexical_block ] [/Users/echristo/debug-tests/bar.cpp]
78 !34 = metadata !{i32 3, i32 18, metadata !33, null}