llvm.org GIT mirror llvm / 09ba28c
IR: Disallow function-local metadata attachments Metadata attachments to instructions cannot be function-local. This is part of PR21532. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223574 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
6 changed file(s) with 17 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
6161 NumberedMetadata[SlotNo] == nullptr)
6262 return Error(MDList[i].Loc, "use of undefined metadata '!" +
6363 Twine(SlotNo) + "'");
64 assert(!NumberedMetadata[SlotNo]->isFunctionLocal() &&
65 "Unexpected function-local metadata");
6466 Inst->setMetadata(MDList[i].MDKind, NumberedMetadata[SlotNo]);
6567 }
6668 }
15281530 if (ParseMetadataListValue(ID, PFS))
15291531 return true;
15301532 assert(ID.Kind == ValID::t_MDNode);
1533 if (ID.MDNodeVal->isFunctionLocal())
1534 return TokError("unexpected function-local metadata");
15311535 Inst->setMetadata(MDK, ID.MDNodeVal);
15321536 } else {
15331537 unsigned NodeID = 0;
23582358 MDKindMap.find(Kind);
23592359 if (I == MDKindMap.end())
23602360 return Error(BitcodeError::InvalidID);
2361 Value *Node = MDValueList.getValueFwdRef(Record[i+1]);
2362 Inst->setMetadata(I->second, cast(Node));
2361 MDNode *Node = cast(MDValueList.getValueFwdRef(Record[i+1]));
2362 if (Node->isFunctionLocal())
2363 // Drop the attachment. This used to be legal, but there's no
2364 // upgrade path.
2365 break;
2366 Inst->setMetadata(I->second, Node);
23632367 if (I->second == LLVMContext::MD_tbaa)
23642368 InstsWithTBAATag.push_back(Inst);
23652369 }
638638
639639 // Handle the case when we're adding/updating metadata on an instruction.
640640 if (Node) {
641 assert(!Node->isFunctionLocal() &&
642 "Function-local metadata cannot be attached to instructions");
641643 LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
642644 assert(!Info.empty() == hasMetadataHashEntry() &&
643645 "HasMetadata bit is wonked");
44 call void @llvm.zonk(metadata !1, i64 0, metadata !1)
55 store i32 0, i32* null, !whatever !0, !whatever_else !{}, !more !{metadata !"hello"}
66 store i32 0, i32* null, !whatever !{metadata !"hello", metadata !1, metadata !{}, metadata !2}
7 ret void, !whatever !{i32 %x}
7 ret void
88 }
99
1010 declare void @llvm.zonk(metadata, i64, metadata) nounwind readnone
0 ; RUN: llvm-link %s %p/metadata-b.ll -S -o - | FileCheck %s
11
22 ; CHECK: define void @foo(i32 %a)
3 ; CHECK: ret void, !attach !0, !also !{i32 %a}
3 ; CHECK: ret void, !attach !0
44 ; CHECK: define void @goo(i32 %b)
5 ; CHECK: ret void, !attach !1, !and !{i32 %b}
5 ; CHECK: ret void, !attach !1
66 ; CHECK: !0 = metadata !{i32 524334, void (i32)* @foo}
77 ; CHECK: !1 = metadata !{i32 524334, void (i32)* @goo}
88
99 define void @foo(i32 %a) nounwind {
1010 entry:
11 ret void, !attach !0, !also !{ i32 %a }
11 ret void, !attach !0
1212 }
1313
1414 !0 = metadata !{i32 524334, void (i32)* @foo}
22
33 define void @goo(i32 %b) nounwind {
44 entry:
5 ret void, !attach !0, !and !{ i32 %b }
5 ret void, !attach !0
66 }
77
88 !0 = metadata !{i32 524334, void (i32)* @goo}