[llvm] 474f20b - [Verifier] Check that !nonnull metadata is empty

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 02:16:59 PST 2023


Author: Nikita Popov
Date: 2023-01-23T11:16:49+01:00
New Revision: 474f20ba26400559e5d99fd4f29926253092f00b

URL: https://github.com/llvm/llvm-project/commit/474f20ba26400559e5d99fd4f29926253092f00b
DIFF: https://github.com/llvm/llvm-project/commit/474f20ba26400559e5d99fd4f29926253092f00b.diff

LOG: [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.

Added: 
    llvm/test/Verifier/nonnull_metadata.ll

Modified: 
    llvm/lib/IR/Verifier.cpp
    llvm/test/Bitcode/compatibility-6.0.ll

Removed: 
    


################################################################################
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<LoadInst>(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 
diff er 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
+}


        


More information about the llvm-commits mailing list