Skip to content

Commit 249337f

Browse files
committed
[Verifier] Handle deref assumptions separately, don't early exit.
For some reason, some of the checks for specific assumbe bundle elements exit early if the check pass, meaning we don't verify other entries. This let a few cases with deref assumptions and non-constant integers slip through. The patch also adds dedicated checks for assume bundles, allowing non-constant integers. This is similar to how align is handled. We could also first just replace the early returns with continues, but that would require adjusting some tests.
1 parent 3187d4d commit 249337f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5517,7 +5517,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
55175517
Call.getOperand(Elem.Begin + 1)->getType()->isPointerTy(),
55185518
"arguments to separate_storage assumptions should be pointers",
55195519
Call);
5520-
return;
5520+
continue;
55215521
}
55225522
Check(Elem.Tag->getKey() == "ignore" ||
55235523
Attribute::isExistingAttribute(Elem.Tag->getKey()),
@@ -5534,7 +5534,16 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
55345534
if (ArgCount == 3)
55355535
Check(Call.getOperand(Elem.Begin + 2)->getType()->isIntegerTy(),
55365536
"third argument should be an integer if present", Call);
5537-
return;
5537+
continue;
5538+
}
5539+
if (Kind == Attribute::Dereferenceable) {
5540+
Check(ArgCount == 2,
5541+
"dereferenceable assumptions should have 2 arguments", Call);
5542+
Check(Call.getOperand(Elem.Begin)->getType()->isPointerTy(),
5543+
"first argument should be a pointer", Call);
5544+
Check(Call.getOperand(Elem.Begin + 1)->getType()->isIntegerTy(),
5545+
"second argument should be an integer", Call);
5546+
continue;
55385547
}
55395548
Check(ArgCount <= 2, "too many arguments", Call);
55405549
if (Kind == Attribute::None)

llvm/test/Verifier/assume-bundles.ll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ define void @func(ptr %P, i32 %P1, ptr %P2, ptr %P3) {
77
; CHECK: tags must be valid attribute names
88
; CHECK: "adazdazd"
99
call void @llvm.assume(i1 true) ["adazdazd"()]
10-
; CHECK: the second argument should be a constant integral value
10+
; CHECK-NOT: call {{.+}}dereferenceable
1111
call void @llvm.assume(i1 true) ["dereferenceable"(ptr %P, i32 %P1)]
12-
; CHECK: the second argument should be a constant integral value
12+
; CHECK: second argument should be an integer
1313
call void @llvm.assume(i1 true) ["dereferenceable"(ptr %P, float 1.5)]
14-
; CHECK: too many arguments
14+
; CHECK: dereferenceable assumptions should have 2 arguments
1515
call void @llvm.assume(i1 true) ["dereferenceable"(ptr %P, i32 8, i32 8)]
16-
; CHECK: this attribute should have 2 arguments
16+
; CHECK: dereferenceable assumptions should have 2 arguments
1717
call void @llvm.assume(i1 true) ["dereferenceable"(ptr %P)]
1818
; CHECK: this attribute has no argument
1919
call void @llvm.assume(i1 true) ["dereferenceable"(ptr %P, i32 4), "cold"(ptr %P)]
@@ -30,8 +30,7 @@ define void @func(ptr %P, i32 %P1, ptr %P2, ptr %P3) {
3030
call void @llvm.assume(i1 true) ["separate_storage"(ptr %P)]
3131
; CHECK: arguments to separate_storage assumptions should be pointers
3232
call void @llvm.assume(i1 true) ["separate_storage"(ptr %P, i32 123)]
33-
; FIXME: The dereferenceable bundle is invalid.
34-
; CHECK-NOT: call {{.+}}dereferenceable
33+
; CHECK: dereferenceable assumptions should have 2 arguments
3534
call void @llvm.assume(i1 true) ["align"(ptr %P, i32 4), "dereferenceable"(ptr %P)]
3635
ret void
3736
}

0 commit comments

Comments
 (0)