[clang] da36603 - [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (#108657)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 06:14:30 PDT 2024


Author: Oleksandr T.
Date: 2024-09-20T09:14:26-04:00
New Revision: da36603148baf37d3625aa030b4c05bf5785cae2

URL: https://github.com/llvm/llvm-project/commit/da36603148baf37d3625aa030b4c05bf5785cae2
DIFF: https://github.com/llvm/llvm-project/commit/da36603148baf37d3625aa030b4c05bf5785cae2.diff

LOG: [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (#108657)

Fixes #108326

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaExpr.cpp
    clang/test/Sema/ext_vector_casts.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f146cb9247a78..0a1d0fd85e7ae0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -403,6 +403,7 @@ Bug Fixes to C++ Support
 - Avoided a redundant friend declaration instantiation under a certain ``consteval`` context. (#GH107175)
 - Fixed an assertion failure in debug mode, and potential crashes in release mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter.
+- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2f7e9c754ce095..66df9c969256a2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,7 +9868,9 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isIntegralType(S.Context)) {
+  if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) {
+    scalarCast = CK_IntegralToBoolean;
+  } else if (vectorEltTy->isIntegralType(S.Context)) {
     if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
         (scalarTy->isIntegerType() &&
          S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) {

diff  --git a/clang/test/Sema/ext_vector_casts.c b/clang/test/Sema/ext_vector_casts.c
index 48440735d88ea9..8bf2737e0bfab1 100644
--- a/clang/test/Sema/ext_vector_casts.c
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16)));
 typedef __typeof__(sizeof(int)) size_t;
 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
 typedef size_t stride4 __attribute__((ext_vector_type(4)));
+typedef _Bool bool4 __attribute__(( ext_vector_type(4) ));
 
 static void test(void) {
     float2 vec2;
@@ -19,6 +20,7 @@ static void test(void) {
     int4 ivec4;
     short8 ish8;
     t3 vec4_3;
+    bool4 bvec4 = 0;
     int *ptr;
     int i;
 
@@ -51,6 +53,9 @@ static void test(void) {
     ivec4 -= ivec4;
     ivec4 |= ivec4;
     ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
+
+    bvec4 != 0; // expected-warning {{inequality comparison result unused}} \
+                // expected-note {{use '|=' to turn this inequality comparison into an or-assignment}}
 }
 
 typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}}


        


More information about the cfe-commits mailing list