Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Sep 20, 2024
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
return true;
} else if (vectorEltTy->isIntegralType(S.Context)) {
if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
(scalarTy->isIntegerType() &&
S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) {
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Sema/ext_vector_casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,7 @@ static void test(void) {
int4 ivec4;
short8 ish8;
t3 vec4_3;
bool4 bvec4 = 0;
int *ptr;
int i;

Expand Down Expand Up @@ -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}} \
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
// 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)}}
Expand Down
Loading