diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-24 21:53:27 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-04-24 21:53:27 +0000 |
commit | 327e9bd399f8c1846b1cb967b03cd9f1e54af1e7 (patch) | |
tree | 153dc00a80913ff4ea8c9994ee0360b306469efd /llvm/unittests | |
parent | e2510cdfe85ee79f97ee49913a16f7ffb4fa40ea (diff) | |
download | bcm5719-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/unittests')
-rw-r--r-- | llvm/unittests/IR/MetadataTest.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index 336822111b8..cb882e76f41 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -17,6 +17,7 @@ #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" +#include "llvm/IR/Verifier.h" #include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" using namespace llvm; @@ -2233,4 +2234,21 @@ TEST_F(FunctionAttachmentTest, dropUnknownMetadata) { EXPECT_FALSE(F->hasMetadata()); } +TEST_F(FunctionAttachmentTest, Verifier) { + Function *F = getFunction("foo"); + F->setMetadata("attach", getTuple()); + + // Confirm this has no body. + ASSERT_TRUE(F->empty()); + + // Functions without a body cannot have metadata attachments (they also can't + // be verified directly, so check that the module fails to verify). + EXPECT_TRUE(verifyModule(*F->getParent())); + + // Functions with a body can. + (void)new UnreachableInst(Context, BasicBlock::Create(Context, "bb", F)); + EXPECT_FALSE(verifyModule(*F->getParent())); + EXPECT_FALSE(verifyFunction(*F)); +} + } |