[clang] f62a8ab - [CIR] Extend VecShuffleOp verifier to catch invalid index (#143262)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 13 13:51:36 PDT 2025
Author: Amr Hesham
Date: 2025-06-13T22:51:33+02:00
New Revision: f62a8ab9304fb8b8b3ac3519a7addd7d3d234b04
URL: https://github.com/llvm/llvm-project/commit/f62a8ab9304fb8b8b3ac3519a7addd7d3d234b04
DIFF: https://github.com/llvm/llvm-project/commit/f62a8ab9304fb8b8b3ac3519a7addd7d3d234b04.diff
LOG: [CIR] Extend VecShuffleOp verifier to catch invalid index (#143262)
Extend the verifier to catch index larger than the size of vector
elements in VecShuffleOp
Issue https://github.com/llvm/llvm-project/issues/136487
Added:
clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
Modified:
clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Removed:
################################################################################
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 8ed0ee92574dc..a685253b7d821 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1643,6 +1643,15 @@ LogicalResult cir::VecShuffleOp::verify() {
<< " and " << getResult().getType() << " don't match";
}
+ const uint64_t maxValidIndex =
+ getVec1().getType().getSize() + getVec2().getType().getSize() - 1;
+ if (llvm::any_of(
+ getIndices().getAsRange<cir::IntAttr>(), [&](cir::IntAttr idxAttr) {
+ return idxAttr.getSInt() != -1 && idxAttr.getUInt() > maxValidIndex;
+ })) {
+ return emitOpError() << ": index for __builtin_shufflevector must be "
+ "less than the total number of vector elements";
+ }
return success();
}
diff --git a/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir b/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
new file mode 100644
index 0000000000000..375b2d3dc563e
--- /dev/null
+++ b/clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
@@ -0,0 +1,16 @@
+// RUN: cir-opt %s -verify-diagnostics -split-input-file
+
+!s32i = !cir.int<s, 32>
+!s64i = !cir.int<s, 64>
+
+module {
+ cir.func @fold_shuffle_vector_op_test() -> !cir.vector<4 x !s32i> {
+ %vec_1 = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<3> : !s32i, #cir.int<5> : !s32i, #cir.int<7> : !s32i]> : !cir.vector<4 x !s32i>
+ %vec_2 = cir.const #cir.const_vector<[#cir.int<2> : !s32i, #cir.int<4> : !s32i, #cir.int<6> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+
+ // expected-error @below {{index for __builtin_shufflevector must be less than the total number of vector elements}}
+ %new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<4 x !s32i>) [#cir.int<9> : !s64i, #cir.int<4> : !s64i,
+ #cir.int<1> : !s64i, #cir.int<5> : !s64i] : !cir.vector<4 x !s32i>
+ cir.return %new_vec : !cir.vector<4 x !s32i>
+ }
+}
More information about the cfe-commits
mailing list