Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -808,6 +808,11 @@ Assert(!MD.getValue()->getType()->isMetadataTy(), "Unexpected metadata round-trip through values", &MD, MD.getValue()); + if (auto *GV = dyn_cast(MD.getValue())) { + Module *ActualM = GV->getParent(); + Assert(ActualM == &M, "module-local metadata used in wrong module", &MD); + } + auto *L = dyn_cast(&MD); if (!L) return;