forked from OSchip/llvm-project
Verify that MDNodes belong to the same context as the Module.
Differential Revision: https://reviews.llvm.org/D99289
This commit is contained in:
parent
a6aae5f7fc
commit
80f6c99a78
|
@ -813,6 +813,9 @@ void Verifier::visitMDNode(const MDNode &MD, AreDebugLocsAllowed AllowLocs) {
|
|||
if (!MDNodes.insert(&MD).second)
|
||||
return;
|
||||
|
||||
Assert(&MD.getContext() == &Context,
|
||||
"MDNode context does not match Module context!", &MD);
|
||||
|
||||
switch (MD.getMetadataID()) {
|
||||
default:
|
||||
llvm_unreachable("Invalid MDNode subclass");
|
||||
|
|
|
@ -238,5 +238,20 @@ TEST(VerifierTest, DetectInvalidDebugInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(VerifierTest, MDNodeWrongContext) {
|
||||
LLVMContext C1, C2;
|
||||
auto *Node = MDNode::get(C1, None);
|
||||
|
||||
Module M("M", C2);
|
||||
auto *NamedNode = M.getOrInsertNamedMetadata("test");
|
||||
NamedNode->addOperand(Node);
|
||||
|
||||
std::string Error;
|
||||
raw_string_ostream ErrorOS(Error);
|
||||
EXPECT_TRUE(verifyModule(M, &ErrorOS));
|
||||
EXPECT_TRUE(StringRef(ErrorOS.str())
|
||||
.startswith("MDNode context does not match Module context!"));
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
} // end namespace llvm
|
||||
|
|
Loading…
Reference in New Issue