https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/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: https://github.com/llvm/llvm-project/issues/107981


>From 6a1ebab4c62fbdc160bab323ebfd9e92998a6c3a Mon Sep 17 00:00:00 2001
From: Joseph Huber <hube...@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               | 7 +++++--
 clang/test/AST/ByteCode/constexpr-vectors.cpp | 7 ++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2944c1a09b32c..c39236cd5f8f8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5601,8 +5601,11 @@ 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);
+      if (resType->isExtVectorType())
+        resType = Context.getExtVectorType(eltType, numResElements);
+      else
+        resType =
+            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);
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to