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

Conversation

andjo403
Copy link
Contributor

fix #99619

@andjo403 andjo403 requested a review from nikic July 24, 2024 20:43
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2024

@llvm/pr-subscribers-llvm-ir

Author: Andreas Jonson (andjo403)

Changes

fix #99619


Full diff: https://github.com/llvm/llvm-project/pull/100465.diff

4 Files Affected:

  • (modified) llvm/lib/AsmParser/LLParser.cpp (+3-2)
  • (modified) llvm/lib/IR/Verifier.cpp (+2)
  • (modified) llvm/test/Assembler/range-attribute-invalid-range.ll (+2-2)
  • (modified) llvm/test/Verifier/range-attr.ll (+12)
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index a886f6e3a4b93..a2e5f3d59663c 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -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;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index c5c407637cbf3..473bbf5f2c3da 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -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);
   }
 }
 
diff --git a/llvm/test/Assembler/range-attribute-invalid-range.ll b/llvm/test/Assembler/range-attribute-invalid-range.ll
index cf6d3f0801838..5969824f2269b 100644
--- a/llvm/test/Assembler/range-attribute-invalid-range.ll
+++ b/llvm/test/Assembler/range-attribute-invalid-range.ll
@@ -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
 }
diff --git a/llvm/test/Verifier/range-attr.ll b/llvm/test/Verifier/range-attr.ll
index f985ab696eacb..5d5a4a328fb85 100644
--- a/llvm/test/Verifier/range-attr.ll
+++ b/llvm/test/Verifier/range-attr.ll
@@ -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
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[IR] Missing assertion for empty range attribute
2 participants