Skip to content

Commit a2ce822

Browse files
committed
Verifier: Fix assertion on range metadata with equal bounds
This only worked if the same values were the min or max. We also seem to be missing proper assembler tests for this.
1 parent f3c9e58 commit a2ce822

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,6 +3927,12 @@ void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) {
39273927

39283928
APInt HighV = High->getValue();
39293929
APInt LowV = Low->getValue();
3930+
3931+
// ConstantRange asserts if the ranges are the same except for the min/max
3932+
// value. Leave the cases it tolerates for the empty range error below.
3933+
Check(LowV != HighV || LowV.isMaxValue() || LowV.isMinValue(),
3934+
"The upper and lower limits cannot be the same value", &I);
3935+
39303936
ConstantRange CurRange(LowV, HighV);
39313937
Check(!CurRange.isEmptySet() && !CurRange.isFullSet(),
39323938
"Range must not be empty!", Range);

llvm/test/Assembler/range.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
2+
3+
define i8 @neg1_zero(ptr %x) {
4+
; CHECK-LABEL: define i8 @neg1_zero
5+
; CHECK-SAME: (ptr [[X:%.*]]) {
6+
; CHECK-NEXT: entry:
7+
; CHECK-NEXT: [[Y:%.*]] = load i8, ptr [[X]], align 1, !range [[RNG0:![0-9]+]]
8+
; CHECK-NEXT: ret i8 [[Y]]
9+
;
10+
entry:
11+
%y = load i8, ptr %x, align 1, !range !0
12+
ret i8 %y
13+
}
14+
15+
define <2 x i8> @neg1_zero_vector(ptr %x) {
16+
; CHECK-LABEL: define <2 x i8> @neg1_zero_vector
17+
; CHECK-SAME: (ptr [[X:%.*]]) {
18+
; CHECK-NEXT: entry:
19+
; CHECK-NEXT: [[Y:%.*]] = load <2 x i8>, ptr [[X]], align 1, !range [[RNG0]]
20+
; CHECK-NEXT: ret <2 x i8> [[Y]]
21+
;
22+
entry:
23+
%y = load <2 x i8>, ptr %x, align 1, !range !0
24+
ret <2 x i8> %y
25+
}
26+
27+
!0 = !{i8 -1, i8 0}
28+
29+
;.
30+
; CHECK: [[RNG0]] = !{i8 -1, i8 0}
31+
;.

llvm/test/Verifier/range-1.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,10 @@ define <2 x i8> @vector_range_wrong_type(ptr %x) {
154154
}
155155
!19 = !{i16 0, i16 10}
156156
; CHECK: Range types must match instruction type!
157+
158+
define i32 @range_assert(ptr %x) {
159+
%y = load i32, ptr %x, !range !20
160+
ret i32 %y
161+
}
162+
; CHECK: The upper and lower limits cannot be the same value{{$}}
163+
!20 = !{i32 123, i32 123}

0 commit comments

Comments
 (0)