[PATCH] D99289: Verify that MDNodes belong to the same context as the Module.
Nick Lewycky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 24 11:58:03 PDT 2021
nickwasmer created this revision.
nickwasmer added reviewers: jyknight, StephenTozer, spatel.
nickwasmer added a project: LLVM.
Herald added subscribers: dexonsmith, hiraditya.
nickwasmer requested review of this revision.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99289
Files:
llvm/lib/IR/Verifier.cpp
llvm/unittests/IR/VerifierTest.cpp
Index: llvm/unittests/IR/VerifierTest.cpp
===================================================================
--- llvm/unittests/IR/VerifierTest.cpp
+++ llvm/unittests/IR/VerifierTest.cpp
@@ -238,5 +238,20 @@
}
}
+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
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -813,6 +813,9 @@
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");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99289.333079.patch
Type: text/x-patch
Size: 1152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210324/3d5f2919/attachment.bin>
More information about the llvm-commits
mailing list