Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 11 additions & 4 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,18 +1586,25 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor adaptor) {
LogicalResult cir::VecShuffleOp::verify() {
// The number of elements in the indices array must match the number of
// elements in the result type.
if (getIndices().size() != getResult().getType().getSize()) {
if (getIndices().size() != getResult().getType().getSize())
return emitOpError() << ": the number of elements in " << getIndices()
<< " and " << getResult().getType() << " don't match";
}

// The element types of the two input vectors and of the result type must
// match.
if (getVec1().getType().getElementType() !=
getResult().getType().getElementType()) {
getResult().getType().getElementType())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have left the braces here since both the condition and the true-expression span multiple lines, but it's really fine either way.

return emitOpError() << ": element types of " << getVec1().getType()
<< " 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();
}
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CIR/IR/invalid-vector-shuffle-wrong-index.cir
Original file line number Diff line number Diff line change
@@ -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>
}
}
Loading