Skip to content

move check of empty/full range attribute to verifier #100465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3109,8 +3109,9 @@ bool LLParser::parseRangeAttr(AttrBuilder &B) {
if (ParseAPSInt(BitWidth, Lower) ||
parseToken(lltok::comma, "expected ','") || ParseAPSInt(BitWidth, Upper))
return true;
if (Lower == Upper)
return tokError("the range should not represent the full or empty set!");
if (Lower == Upper && !(Lower.isMaxValue() || Lower.isMinValue()))
return tokError("the range represent the full or empty set but they aren't "
"min or max value!");

if (parseToken(lltok::rparen, "expected ')'"))
return true;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,8 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
Check(Ty->isIntOrIntVectorTy(CR.getBitWidth()),
"Range bit width must match type bit width!", V);
Check(!CR.isEmptySet(), "Range must not be empty!", V);
Check(!CR.isFullSet(), "Range must not be full!", V);
}
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Assembler/range-attribute-invalid-range.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s

; CHECK: the range should not represent the full or empty set!
define void @range_empty(i8 range(i8 0, 0) %a) {
; CHECK: the range represent the full or empty set but they aren't min or max value!
define void @range_empty(i8 range(i8 3, 3) %a) {
ret void
}
12 changes: 12 additions & 0 deletions llvm/test/Verifier/range-attr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,15 @@ define void @bit_widths_do_not_match_vector(<4 x i32> range(i8 1, 0) %a) {
define void @not-integer-type(ptr range(i8 1, 0) %a) {
ret void
}

; CHECK: Range must not be empty!
; CHECK-NEXT: ptr @empty_range
define void @empty_range(i8 range(i8 0, 0) %a) {
ret void
}

; CHECK: Range must not be full!
; CHECK-NEXT: ptr @full_range
define void @full_range(i8 range(i8 -1, -1) %a) {
ret void
}
Loading