[llvm] move check of empty/full range attribute to verifier (PR #100465)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 13:43:20 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Andreas Jonson (andjo403)

<details>
<summary>Changes</summary>

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
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list