summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-04-24 21:53:27 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-04-24 21:53:27 +0000
commit327e9bd399f8c1846b1cb967b03cd9f1e54af1e7 (patch)
tree153dc00a80913ff4ea8c9994ee0360b306469efd /llvm/lib
parente2510cdfe85ee79f97ee49913a16f7ffb4fa40ea (diff)
downloadbcm5719-llvm-327e9bd399f8c1846b1cb967b03cd9f1e54af1e7.tar.gz
bcm5719-llvm-327e9bd399f8c1846b1cb967b03cd9f1e54af1e7.zip
Verifier: Function metadata attachments require a body
Add a verifier check that only functions with bodies have metadata attachments. This should help catch bugs in frontends and transformation passes. Part of PR23340. llvm-svn: 235784
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/Verifier.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 099cbd9e0fe..afce3e2bf56 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1669,11 +1669,20 @@ void Verifier::visitFunction(const Function &F) {
"Function takes metadata but isn't an intrinsic", I, &F);
}
+ // Get the function metadata attachments.
+ SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
+ F.getAllMetadata(MDs);
+ assert(F.hasMetadata() != MDs.empty() && "Bit out-of-sync");
+
if (F.isMaterializable()) {
// Function has a body somewhere we can't see.
+ Assert(MDs.empty(), "unmaterialized function cannot have metadata", &F,
+ MDs.empty() ? nullptr : MDs.front().second);
} else if (F.isDeclaration()) {
Assert(F.hasExternalLinkage() || F.hasExternalWeakLinkage(),
"invalid linkage type for function declaration", &F);
+ Assert(MDs.empty(), "function without a body cannot have metadata", &F,
+ MDs.empty() ? nullptr : MDs.front().second);
} else {
// Verify that this function (which has a body) is not named "llvm.*". It
// is not legal to define intrinsics.
@@ -1689,6 +1698,10 @@ void Verifier::visitFunction(const Function &F) {
Assert(!BlockAddress::lookup(Entry)->isConstantUsed(),
"blockaddress may not be used with the entry block!", Entry);
}
+
+ // Visit metadata attachments.
+ for (const auto &I : MDs)
+ visitMDNode(*I.second);
}
// If this function is actually an intrinsic, verify that it is only used in
OpenPOWER on IntegriCloud