Skip to content

Commit da36603

Browse files
authored
[Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (llvm#108657)
Fixes llvm#108326
1 parent 03635b3 commit da36603

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ Bug Fixes to C++ Support
403403
- Avoided a redundant friend declaration instantiation under a certain ``consteval`` context. (#GH107175)
404404
- Fixed an assertion failure in debug mode, and potential crashes in release mode, when
405405
diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter.
406+
- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326)
406407

407408
Bug Fixes to AST Handling
408409
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9868,7 +9868,9 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
98689868
// if necessary.
98699869
CastKind scalarCast = CK_NoOp;
98709870

9871-
if (vectorEltTy->isIntegralType(S.Context)) {
9871+
if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) {
9872+
scalarCast = CK_IntegralToBoolean;
9873+
} else if (vectorEltTy->isIntegralType(S.Context)) {
98729874
if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
98739875
(scalarTy->isIntegerType() &&
98749876
S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) {

clang/test/Sema/ext_vector_casts.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16)));
1111
typedef __typeof__(sizeof(int)) size_t;
1212
typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
1313
typedef size_t stride4 __attribute__((ext_vector_type(4)));
14+
typedef _Bool bool4 __attribute__(( ext_vector_type(4) ));
1415

1516
static void test(void) {
1617
float2 vec2;
@@ -19,6 +20,7 @@ static void test(void) {
1920
int4 ivec4;
2021
short8 ish8;
2122
t3 vec4_3;
23+
bool4 bvec4 = 0;
2224
int *ptr;
2325
int i;
2426

@@ -51,6 +53,9 @@ static void test(void) {
5153
ivec4 -= ivec4;
5254
ivec4 |= ivec4;
5355
ivec4 += ptr; // expected-error {{cannot convert between vector and non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
56+
57+
bvec4 != 0; // expected-warning {{inequality comparison result unused}} \
58+
// expected-note {{use '|=' to turn this inequality comparison into an or-assignment}}
5459
}
5560

5661
typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // expected-error{{invalid vector element type 'float2' (vector of 2 'float' values)}}

0 commit comments

Comments
 (0)