From 474f20ba26400559e5d99fd4f29926253092f00b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 20 Jan 2023 17:06:46 +0100 Subject: [PATCH] [Verifier] Check that !nonnull metadata is empty !nonnull expectes an empty metadata argument, so check that this is the case in the verifier. This came up as a problem in https://reviews.llvm.org/D141386. This requires dropping the verifier call in the compatibility-6.0.ll test (which is not present in any of the other bitcode compatibility tests). The original input unfortunately used typo'd nonnull metadata. --- llvm/lib/IR/Verifier.cpp | 3 ++- llvm/test/Bitcode/compatibility-6.0.ll | 1 - llvm/test/Verifier/nonnull_metadata.ll | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Verifier/nonnull_metadata.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 233e10b..83e42bc 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 09fe08f..227672d 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 0000000..9ef67dc --- /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 +} -- 2.7.4