diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 233e10bb223af..83e42bc184ff2 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -4832,13 +4832,14 @@ void Verifier::visitInstruction(Instruction &I) { "invariant.group metadata is only for loads and stores", &I); } - if (I.getMetadata(LLVMContext::MD_nonnull)) { + if (MDNode *MD = I.getMetadata(LLVMContext::MD_nonnull)) { Check(I.getType()->isPointerTy(), "nonnull applies only to pointer types", &I); Check(isa(I), "nonnull applies only to load instructions, use attributes" " for calls or invokes", &I); + Check(MD->getNumOperands() == 0, "nonnull metadata must be empty", &I); } if (MDNode *MD = I.getMetadata(LLVMContext::MD_dereferenceable)) diff --git a/llvm/test/Bitcode/compatibility-6.0.ll b/llvm/test/Bitcode/compatibility-6.0.ll index 09fe08ff10f18..227672da489dc 100644 --- a/llvm/test/Bitcode/compatibility-6.0.ll +++ b/llvm/test/Bitcode/compatibility-6.0.ll @@ -3,7 +3,6 @@ ; N.b: This is 6.0-compatible IR. The CHECK lines occasionally differ from ; the IR used to generate the bitcode, and may need to be updated. -; RUN: opt -passes=verify -disable-output < %s.bc ; RUN: llvm-dis < %s.bc | FileCheck %s target datalayout = "E" diff --git a/llvm/test/Verifier/nonnull_metadata.ll b/llvm/test/Verifier/nonnull_metadata.ll new file mode 100644 index 0000000000000..9ef67dc163c59 --- /dev/null +++ b/llvm/test/Verifier/nonnull_metadata.ll @@ -0,0 +1,21 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +declare ptr @dummy() + +; CHECK: nonnull applies only to pointer types +define void @test_not_pointer(ptr %p) { + load i32, ptr %p, !nonnull !{} + ret void +} + +; CHECK: nonnull applies only to load instructions, use attributes for calls or invokes +define void @test_not_load() { + call ptr @dummy(), !nonnull !{} + ret void +} + +; CHECK: nonnull metadata must be empty +define void @test_invalid_arg(ptr %p) { + load ptr, ptr %p, !nonnull !{i32 0} + ret void +}