[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 19 12:19:27 PDT 2024
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/108657
>From 70d1be2a2a0f2f44cdd70bfb4397e7a36f1c9f30 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Sat, 14 Sep 2024 01:46:28 +0300
Subject: [PATCH 1/3] [Clang] prevented assertion failure by handling integral
to boolean conversions for boolean vectors
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Sema/SemaExpr.cpp | 7 ++++++-
clang/test/Sema/ext_vector_casts.c | 5 +++++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3929a9fb599259..e9d8d1b789506d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -386,6 +386,7 @@ Bug Fixes to C++ Support
- Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
- Fixed a crash when clang tries to subtitute parameter pack while retaining the parameter
pack. #GH63819, #GH107560
+- 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 8f3e15cc9a9bb7..15b233212b770b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,7 +9868,12 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
// if necessary.
CastKind scalarCast = CK_NoOp;
- if (vectorEltTy->isIntegralType(S.Context)) {
+ if (vectorEltTy->isBooleanType()) {
+ if (scalarTy->isIntegralType(S.Context))
+ scalarCast = CK_IntegralToBoolean;
+ else if (!scalarTy->isBooleanType())
+ return true;
+ } 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..6338035a61aad6 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 float 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)}}
>From b7dc3966847429864fc56886370833afd40e38a5 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Tue, 17 Sep 2024 13:36:52 +0300
Subject: [PATCH 2/3] eliminate redundant logic that disallows non-boolean
scalar casts
---
clang/lib/Sema/SemaExpr.cpp | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 15b233212b770b..17dd3aeb6e3b6f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,11 +9868,8 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
// if necessary.
CastKind scalarCast = CK_NoOp;
- if (vectorEltTy->isBooleanType()) {
- if (scalarTy->isIntegralType(S.Context))
- scalarCast = CK_IntegralToBoolean;
- else if (!scalarTy->isBooleanType())
- return true;
+ if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) {
+ scalarCast = CK_IntegralToBoolean;
} else if (vectorEltTy->isIntegralType(S.Context)) {
if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
(scalarTy->isIntegerType() &&
>From d102f1a5db12e0066f70a3d30e467961baa6cf1f Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Thu, 19 Sep 2024 22:18:57 +0300
Subject: [PATCH 3/3] fix typo
---
clang/test/Sema/ext_vector_casts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/Sema/ext_vector_casts.c b/clang/test/Sema/ext_vector_casts.c
index 6338035a61aad6..8bf2737e0bfab1 100644
--- a/clang/test/Sema/ext_vector_casts.c
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -11,7 +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 float bool4 __attribute__(( ext_vector_type(4) ));
+typedef _Bool bool4 __attribute__(( ext_vector_type(4) ));
static void test(void) {
float2 vec2;
More information about the cfe-commits
mailing list