Skip to content

Commit c704dab

Browse files
authored
[Clang] Fix incorrect return type for __builtin_shufflevector (#154817)
Summary: The `__builtin_shufflevector` call would return a GCC vector in all cases where the vector type was increased. Change this to preserve whether or not this was an extended vector. Fixes: #107981
1 parent 8fa55a0 commit c704dab

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5601,8 +5601,10 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
56015601
TheCall->getArg(1)->getEndLoc()));
56025602
} else if (numElements != numResElements) {
56035603
QualType eltType = LHSType->castAs<VectorType>()->getElementType();
5604-
resType =
5605-
Context.getVectorType(eltType, numResElements, VectorKind::Generic);
5604+
resType = resType->isExtVectorType()
5605+
? Context.getExtVectorType(eltType, numResElements)
5606+
: Context.getVectorType(eltType, numResElements,
5607+
VectorKind::Generic);
56065608
}
56075609
}
56085610

clang/test/AST/ByteCode/constexpr-vectors.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ using FourFloatsExtVec __attribute__((ext_vector_type(4))) = float;
1515
using FourDoublesExtVec __attribute__((ext_vector_type(4))) = double;
1616
using FourI128ExtVec __attribute__((ext_vector_type(4))) = __int128;
1717

18-
1918
// Next a series of tests to make sure these operations are usable in
2019
// constexpr functions. Template instantiations don't emit Winvalid-constexpr,
2120
// so we have to do these as macros.
@@ -875,3 +874,9 @@ void BoolVecUsage() {
875874
constexpr auto k = ~FourBoolsExtVec{true, false, true, false};
876875
static_assert(k[0] == false && k[1] == true && k[2] == false && k[3] == true, "");
877876
}
877+
878+
using EightBoolsExtVec __attribute__((ext_vector_type(8))) = bool;
879+
void BoolVecShuffle() {
880+
constexpr EightBoolsExtVec a = __builtin_shufflevector(
881+
FourBoolsExtVec{}, FourBoolsExtVec{}, 0, 1, 2, 3, 4, 5, 6, 7);
882+
}

0 commit comments

Comments
 (0)