Skip to content

Commit 578fb25

Browse files
committed
[Sema][SVE] Allow ?: to select between SVE types in C
When compiling C, a ?: between two values of the same SVE type currently gives an error such as: incompatible operand types ('svint8_t' (aka '__SVInt8_t') and 'svint8_t') It's supposed to be valid to select between (cv-qualified versions of) the same SVE type, so this patch adds that case. These expressions already work for C++ and are tested by SemaCXX/sizeless-1.cpp. Differential Revision: https://reviews.llvm.org/D76693
1 parent 8f1651c commit 578fb25

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7586,6 +7586,11 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
75867586
/*IsIntFirstExpr=*/false))
75877587
return LHSTy;
75887588

7589+
// Allow ?: operations in which both operands have the same
7590+
// built-in sizeless type.
7591+
if (LHSTy->isSizelessBuiltinType() && LHSTy == RHSTy)
7592+
return LHSTy;
7593+
75897594
// Emit a better diagnostic if one of the expressions is a null pointer
75907595
// constant and the other is not a pointer type. In this case, the user most
75917596
// likely forgot to take the address of the other expression.

clang/test/Sema/sizeless-1.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ void func(int sel) {
126126

127127
const_volatile_int8 = local_int8; // expected-error {{cannot assign to variable 'const_volatile_int8' with const-qualified type 'const volatile svint8_t'}}
128128

129+
init_int8 = sel ? init_int8 : local_int8;
130+
init_int8 = sel ? init_int8 : const_int8;
131+
init_int8 = sel ? volatile_int8 : const_int8;
132+
init_int8 = sel ? volatile_int8 : const_volatile_int8;
133+
129134
pass_int8(local_int8);
130135
pass_int8(local_int16); // expected-error {{passing 'svint16_t' (aka '__SVInt16_t') to parameter of incompatible type 'svint8_t'}}
131136

0 commit comments

Comments
 (0)