[llvm] move check of empty/full range attribute to verifier (PR #100465)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 13:42:45 PDT 2024
https://github.com/andjo403 created https://github.com/llvm/llvm-project/pull/100465
fix #99619
>From 13dcd6f8e0f8e0a04883b782ed0eead0dcd66559 Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Wed, 24 Jul 2024 22:40:53 +0200
Subject: [PATCH] move check of empty/full range attribute to verifier
---
llvm/lib/AsmParser/LLParser.cpp | 5 +++--
llvm/lib/IR/Verifier.cpp | 2 ++
llvm/test/Assembler/range-attribute-invalid-range.ll | 4 ++--
llvm/test/Verifier/range-attr.ll | 12 ++++++++++++
4 files changed, 19 insertions(+), 4 deletions(-)
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
+}
More information about the llvm-commits
mailing list