[llvm] 92b94a6 - [Verifier] Only allow invariant.group metadata on stores and loads
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 2 12:50:02 PDT 2021
Author: Arthur Eubanks
Date: 2021-09-02T12:49:04-07:00
New Revision: 92b94a6d0c33427f90a021cd918d4b450cd444eb
URL: https://github.com/llvm/llvm-project/commit/92b94a6d0c33427f90a021cd918d4b450cd444eb
DIFF: https://github.com/llvm/llvm-project/commit/92b94a6d0c33427f90a021cd918d4b450cd444eb.diff
LOG: [Verifier] Only allow invariant.group metadata on stores and loads
As specified by https://llvm.org/docs/LangRef.html#invariant-group-metadata.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D109182
Added:
llvm/test/Verifier/invariant.group.ll
Modified:
llvm/lib/IR/Verifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index cdf9dc522f9b6..afdf2258138ef 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4470,6 +4470,11 @@ void Verifier::visitInstruction(Instruction &I) {
visitRangeMetadata(I, Range, I.getType());
}
+ if (I.hasMetadata(LLVMContext::MD_invariant_group)) {
+ Assert(isa<LoadInst>(I) || isa<StoreInst>(I),
+ "invariant.group metadata is only for loads and stores", &I);
+ }
+
if (I.getMetadata(LLVMContext::MD_nonnull)) {
Assert(I.getType()->isPointerTy(), "nonnull applies only to pointer types",
&I);
diff --git a/llvm/test/Verifier/invariant.group.ll b/llvm/test/Verifier/invariant.group.ll
new file mode 100644
index 0000000000000..2b2a1bc6a8899
--- /dev/null
+++ b/llvm/test/Verifier/invariant.group.ll
@@ -0,0 +1,14 @@
+; RUN: not opt -passes=verify -disable-output < %s 2>&1 | FileCheck %s
+
+; CHECK: invariant.group metadata is only for loads and stores
+; CHECK-NEXT: alloca
+; CHECK-NEXT: invariant.group metadata is only for loads and stores
+; CHECK-NEXT: ret void
+define void @f() {
+ %a = alloca i32, !invariant.group !0
+ %b = load i32, i32* %a, !invariant.group !0
+ store i32 43, i32* %a, !invariant.group !0
+ ret void, !invariant.group !0
+}
+
+!0 = !{}
More information about the llvm-commits
mailing list