unsigned Column, Metadata *Scope,
Metadata *InlinedAt, StorageType Storage,
bool ShouldCreate = true);
+ static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
+ unsigned Column, MDLocalScope *Scope,
+ MDLocation *InlinedAt, StorageType Storage,
+ bool ShouldCreate = true) {
+ return getImpl(Context, Line, Column, static_cast<Metadata *>(Scope),
+ static_cast<Metadata *>(InlinedAt), Storage, ShouldCreate);
+ }
TempMDLocation cloneImpl() const {
return getTemporary(getContext(), getLine(), getColumn(), getScope(),
(unsigned Line, unsigned Column, Metadata *Scope,
Metadata *InlinedAt = nullptr),
(Line, Column, Scope, InlinedAt))
+ DEFINE_MDNODE_GET(MDLocation,
+ (unsigned Line, unsigned Column, MDLocalScope *Scope,
+ MDLocation *InlinedAt = nullptr),
+ (Line, Column, Scope, InlinedAt))
/// \brief Return a (temporary) clone of this.
TempMDLocation clone() const { return cloneImpl(); }
unsigned getLine() const { return SubclassData32; }
unsigned getColumn() const { return SubclassData16; }
- Metadata *getScope() const { return getOperand(0); }
- Metadata *getInlinedAt() const {
+ MDLocalScope *getScope() const {
+ return cast_or_null<MDLocalScope>(getRawScope());
+ }
+ MDLocation *getInlinedAt() const {
+ return cast_or_null<MDLocation>(getRawInlinedAt());
+ }
+
+ Metadata *getRawScope() const { return getOperand(0); }
+ Metadata *getRawInlinedAt() const {
if (getNumOperands() == 2)
return getOperand(1);
return nullptr;
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS
- auto get = (IsDistinct ? MDLocation::getDistinct : MDLocation::get);
- Result = get(Context, line.Val, column.Val, scope.Val, inlinedAt.Val);
+ Result = GET_OR_DISTINCT(
+ MDLocation, (Context, line.Val, column.Val, scope.Val, inlinedAt.Val));
return false;
}
if (Record.size() != 5)
return Error("Invalid record");
- auto get = Record[0] ? MDLocation::getDistinct : MDLocation::get;
unsigned Line = Record[1];
unsigned Column = Record[2];
MDNode *Scope = cast<MDNode>(MDValueList.getValueFwdRef(Record[3]));
Metadata *InlinedAt =
Record[4] ? MDValueList.getValueFwdRef(Record[4] - 1) : nullptr;
- MDValueList.AssignValue(get(Context, Line, Column, Scope, InlinedAt),
- NextMDValueNo++);
+ MDValueList.AssignValue(
+ GET_OR_DISTINCT(MDLocation, Record[0],
+ (Context, Line, Column, Scope, InlinedAt)),
+ NextMDValueNo++);
break;
}
case bitc::METADATA_GENERIC_DEBUG: {
if (DL->getColumn())
Out << FS << "column: " << DL->getColumn();
Out << FS << "scope: ";
- WriteAsOperandInternal(Out, DL->getScope(), TypePrinter, Machine, Context);
- if (DL->getInlinedAt()) {
+ WriteAsOperandInternal(Out, DL->getRawScope(), TypePrinter, Machine, Context);
+ if (auto *IA = DL->getRawInlinedAt()) {
Out << FS << "inlinedAt: ";
- WriteAsOperandInternal(Out, DL->getInlinedAt(), TypePrinter, Machine,
- Context);
+ WriteAsOperandInternal(Out, IA, TypePrinter, Machine, Context);
}
Out << ")";
}
: Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
MDNodeKeyImpl(const MDLocation *L)
- : Line(L->getLine()), Column(L->getColumn()), Scope(L->getScope()),
- InlinedAt(L->getInlinedAt()) {}
+ : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
+ InlinedAt(L->getRawInlinedAt()) {}
bool isKeyOf(const MDLocation *RHS) const {
return Line == RHS->getLine() && Column == RHS->getColumn() &&
- Scope == RHS->getScope() && InlinedAt == RHS->getInlinedAt();
+ Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
}
unsigned getHashValue() const {
return hash_combine(Line, Column, Scope, InlinedAt);
}
void Verifier::visitMDLocation(const MDLocation &N) {
- Assert(N.getScope(), "location requires a valid scope", &N);
- if (auto *IA = N.getInlinedAt())
+ Assert(N.getRawScope() && isa<MDLocalScope>(N.getRawScope()),
+ "location requires a valid scope", &N, N.getRawScope());
+ if (auto *IA = N.getRawInlinedAt())
Assert(isa<MDLocation>(IA), "inlined-at should be a location", &N, IA);
}
; CHECK: !named = !{!0, !1, !1, !2, !2, !3, !3, !4}
!named = !{!0, !1, !2, !3, !4, !5, !6, !7}
-; CHECK: !0 = !{}
-!0 = !{}
+; CHECK: !0 = !MDSubprogram(
+!0 = !MDSubprogram()
; CHECK-NEXT: !1 = !MDLocation(line: 3, column: 7, scope: !0)
!1 = !MDLocation(line: 3, column: 7, scope: !0)
}
!0 = !MDLocation(line: 662302, column: 26, scope: !1)
-!1 = !{i32 4, !"foo"}
+!1 = !MDSubprogram(name: "foo")
declare void @llvm.dbg.func.start(metadata) nounwind readnone
!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
-!0 = !{} ; Use this as a scope.
+!0 = !MDSubprogram() ; Use this as a scope.
!1 = !MDLocation(line: 3, column: 7, scope: !0)
!2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
!3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
-!4 = distinct !{} ; Test actual remapping.
+!4 = distinct !MDSubprogram() ; Test actual remapping.
!5 = !MDLocation(line: 3, column: 7, scope: !4)
!6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
!7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
; CHECK: !named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9, !0, !1, !2, !3, !10, !11, !12, !13, !14, !15}
!named = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
-; CHECK: !0 = !{}
+; CHECK: !0 = !MDSubprogram(
; CHECK-NEXT: !1 = !MDLocation(line: 3, column: 7, scope: !0)
; CHECK-NEXT: !2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
; CHECK-NEXT: !3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
-; CHECK-NEXT: !4 = distinct !{}
+; CHECK-NEXT: !4 = distinct !MDSubprogram(
; CHECK-NEXT: !5 = !MDLocation(line: 3, column: 7, scope: !4)
; CHECK-NEXT: !6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
; CHECK-NEXT: !7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
; CHECK-NEXT: !8 = distinct !MDLocation(line: 3, column: 7, scope: !0)
; CHECK-NEXT: !9 = distinct !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !8)
-; CHECK-NEXT: !10 = distinct !{}
+; CHECK-NEXT: !10 = distinct !MDSubprogram(
; CHECK-NEXT: !11 = !MDLocation(line: 3, column: 7, scope: !10)
; CHECK-NEXT: !12 = !MDLocation(line: 3, column: 7, scope: !10, inlinedAt: !11)
; CHECK-NEXT: !13 = !MDLocation(line: 3, column: 7, scope: !10, inlinedAt: !12)
; CHECK-NEXT: !14 = distinct !MDLocation(line: 3, column: 7, scope: !0)
; CHECK-NEXT: !15 = distinct !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !14)
-!0 = !{} ; Use this as a scope.
+!0 = !MDSubprogram() ; Use this as a scope.
!1 = !MDLocation(line: 3, column: 7, scope: !0)
!2 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !1)
!3 = !MDLocation(line: 3, column: 7, scope: !0, inlinedAt: !2)
-!4 = distinct !{} ; Test actual remapping.
+!4 = distinct !MDSubprogram() ; Test actual remapping.
!5 = !MDLocation(line: 3, column: 7, scope: !4)
!6 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !5)
!7 = !MDLocation(line: 3, column: 7, scope: !4, inlinedAt: !6)
Metadata *MDs[] = {MD1, MD2};
return MDNode::get(Context, MDs);
}
+
+ MDSubprogram *getSubprogram() {
+ return MDSubprogram::getDistinct(Context, nullptr, "", "", nullptr, 0,
+ nullptr, false, false, 0, nullptr, 0, 0, 0,
+ 0);
+ }
};
typedef MetadataTest MDStringTest;
typedef MetadataTest MDLocationTest;
TEST_F(MDLocationTest, Overflow) {
- MDNode *N = MDNode::get(Context, None);
+ MDSubprogram *N = getSubprogram();
{
MDLocation *L = MDLocation::get(Context, 2, 7, N);
EXPECT_EQ(2u, L->getLine());
}
TEST_F(MDLocationTest, getDistinct) {
- MDNode *N = MDNode::get(Context, None);
+ MDNode *N = getSubprogram();
MDLocation *L0 = MDLocation::getDistinct(Context, 2, 7, N);
EXPECT_TRUE(L0->isDistinct());
MDLocation *L1 = MDLocation::get(Context, 2, 7, N);