mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235784 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user