[clang] [Clang] Fix incorrect return type for `__builtin_shufflevector` (PR #154817)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 21 13:12:02 PDT 2025
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/154817
>From d2eceb10f6bb33c28f4891b0664e4978b7a76c88 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Thu, 21 Aug 2025 13:14:03 -0500
Subject: [PATCH] [Clang] Fix incorrect return type for
`__builtin_shufflevector`
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: https://github.com/llvm/llvm-project/issues/107981
---
clang/lib/Sema/SemaChecking.cpp | 6 ++++--
clang/test/AST/ByteCode/constexpr-vectors.cpp | 7 ++++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2944c1a09b32c..1d3cd58c77dc5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5601,8 +5601,10 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
TheCall->getArg(1)->getEndLoc()));
} else if (numElements != numResElements) {
QualType eltType = LHSType->castAs<VectorType>()->getElementType();
- resType =
- Context.getVectorType(eltType, numResElements, VectorKind::Generic);
+ resType = resType->isExtVectorType()
+ ? Context.getExtVectorType(eltType, numResElements)
+ : Context.getVectorType(eltType, numResElements,
+ VectorKind::Generic);
}
}
diff --git a/clang/test/AST/ByteCode/constexpr-vectors.cpp b/clang/test/AST/ByteCode/constexpr-vectors.cpp
index f19adad3323f2..81ec6aac4bee3 100644
--- a/clang/test/AST/ByteCode/constexpr-vectors.cpp
+++ b/clang/test/AST/ByteCode/constexpr-vectors.cpp
@@ -15,7 +15,6 @@ using FourFloatsExtVec __attribute__((ext_vector_type(4))) = float;
using FourDoublesExtVec __attribute__((ext_vector_type(4))) = double;
using FourI128ExtVec __attribute__((ext_vector_type(4))) = __int128;
-
// Next a series of tests to make sure these operations are usable in
// constexpr functions. Template instantiations don't emit Winvalid-constexpr,
// so we have to do these as macros.
@@ -875,3 +874,9 @@ void BoolVecUsage() {
constexpr auto k = ~FourBoolsExtVec{true, false, true, false};
static_assert(k[0] == false && k[1] == true && k[2] == false && k[3] == true, "");
}
+
+using EightBoolsExtVec __attribute__((ext_vector_type(8))) = bool;
+void BoolVecShuffle() {
+ constexpr EightBoolsExtVec a = __builtin_shufflevector(
+ FourBoolsExtVec{}, FourBoolsExtVec{}, 0, 1, 2, 3, 4, 5, 6, 7);
+}
More information about the cfe-commits
mailing list