Skip to content

Commit b464767

Browse files
aeubanksmemfrob
authored andcommitted
[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
1 parent 9ccd7c3 commit b464767

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,6 +4470,11 @@ void Verifier::visitInstruction(Instruction &I) {
44704470
visitRangeMetadata(I, Range, I.getType());
44714471
}
44724472

4473+
if (I.hasMetadata(LLVMContext::MD_invariant_group)) {
4474+
Assert(isa<LoadInst>(I) || isa<StoreInst>(I),
4475+
"invariant.group metadata is only for loads and stores", &I);
4476+
}
4477+
44734478
if (I.getMetadata(LLVMContext::MD_nonnull)) {
44744479
Assert(I.getType()->isPointerTy(), "nonnull applies only to pointer types",
44754480
&I);

llvm/test/Verifier/invariant.group.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: not opt -passes=verify -disable-output < %s 2>&1 | FileCheck %s
2+
3+
; CHECK: invariant.group metadata is only for loads and stores
4+
; CHECK-NEXT: alloca
5+
; CHECK-NEXT: invariant.group metadata is only for loads and stores
6+
; CHECK-NEXT: ret void
7+
define void @f() {
8+
%a = alloca i32, !invariant.group !0
9+
%b = load i32, i32* %a, !invariant.group !0
10+
store i32 43, i32* %a, !invariant.group !0
11+
ret void, !invariant.group !0
12+
}
13+
14+
!0 = !{}

0 commit comments

Comments
 (0)