https://github.com/wsehjk updated 
https://github.com/llvm/llvm-project/pull/130400

>From 2bae9c70106ffb96dc237ee539dd7e3438025b01 Mon Sep 17 00:00:00 2001
From: wang shiwen <wse1714401...@gmail.com>
Date: Sat, 8 Mar 2025 15:40:22 +0800
Subject: [PATCH] disable unary, vector mask

---
 clang/lib/Sema/SemaChecking.cpp              | 24 +++++---------------
 clang/test/Sema/constant_builtins_vector.cpp |  4 ++++
 2 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9cac9cf5c4df7..d30ded065228d 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5169,16 +5169,15 @@ bool Sema::BuiltinComplex(CallExpr *TheCall) {
 
 /// BuiltinShuffleVector - Handle __builtin_shufflevector.
 // This is declared to take (...), so we have to check everything.
+// disable unary, vector mask: (lhs, mask)
+// allow binary, scalar mask: (lhs, rhs, index, ..., index)
 ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) {
-  if (TheCall->getNumArgs() < 2)
+  if (TheCall->getNumArgs() <= 2)
     return ExprError(Diag(TheCall->getEndLoc(),
                           diag::err_typecheck_call_too_few_args_at_least)
-                     << 0 /*function call*/ << 2 << TheCall->getNumArgs()
+                     << 0 /*function call*/ << 3 << TheCall->getNumArgs()
                      << /*is non object*/ 0 << TheCall->getSourceRange());
 
-  // Determine which of the following types of shufflevector we're checking:
-  // 1) unary, vector mask: (lhs, mask)
-  // 2) binary, scalar mask: (lhs, rhs, index, ..., index)
   QualType resType = TheCall->getArg(0)->getType();
   unsigned numElements = 0;
 
@@ -5197,19 +5196,8 @@ ExprResult Sema::BuiltinShuffleVector(CallExpr *TheCall) 
{
     numElements = LHSType->castAs<VectorType>()->getNumElements();
     unsigned numResElements = TheCall->getNumArgs() - 2;
 
-    // Check to see if we have a call with 2 vector arguments, the unary 
shuffle
-    // with mask.  If so, verify that RHS is an integer vector type with the
-    // same number of elts as lhs.
-    if (TheCall->getNumArgs() == 2) {
-      if (!RHSType->hasIntegerRepresentation() ||
-          RHSType->castAs<VectorType>()->getNumElements() != numElements)
-        return ExprError(Diag(TheCall->getBeginLoc(),
-                              diag::err_vec_builtin_incompatible_vector)
-                         << TheCall->getDirectCallee()
-                         << /*isMorethantwoArgs*/ false
-                         << SourceRange(TheCall->getArg(1)->getBeginLoc(),
-                                        TheCall->getArg(1)->getEndLoc()));
-    } else if (!Context.hasSameUnqualifiedType(LHSType, RHSType)) {
+
+    if (!Context.hasSameUnqualifiedType(LHSType, RHSType) ) {
       return ExprError(Diag(TheCall->getBeginLoc(),
                             diag::err_vec_builtin_incompatible_vector)
                        << TheCall->getDirectCallee()
diff --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index 8659fa9e46612..d74b1d828c09c 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -692,6 +692,10 @@ constexpr vector4char vector4charConst1 = {0, 1, 2, 3};
 constexpr vector4char vector4charConst2 = {4, 5, 6, 7};
 constexpr vector8char vector8intConst = {8, 9, 10, 11, 12, 13, 14, 15};
 
+
+constexpr vector4char vectorShuffle =
+    __builtin_shufflevector(vector4charConst1, vector4charConst2);// 
expected-error {{too few arguments to function call, expected at least 3, have 
2}}
+
 constexpr vector4char vectorShuffle1 =
     __builtin_shufflevector(vector4charConst1, vector4charConst2, 0, 1, 2, 3);
 static_assert(__builtin_bit_cast(unsigned, vectorShuffle1) ==

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

Reply via email to