forked from OSchip/llvm-project
[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
This commit is contained in:
parent
85b732b559
commit
92b94a6d0c
|
@ -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);
|
||||
|
|
|
@ -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 = !{}
|
Loading…
Reference in New Issue