[clang] 578fb25 - [Sema][SVE] Allow ?: to select between SVE types in C
Richard Sandiford via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 25 03:52:04 PDT 2020
Author: Richard Sandiford
Date: 2020-03-25T10:31:09Z
New Revision: 578fb2501a66e407187ec0ac4da20995265f91c8
URL: https://github.com/llvm/llvm-project/commit/578fb2501a66e407187ec0ac4da20995265f91c8
DIFF: https://github.com/llvm/llvm-project/commit/578fb2501a66e407187ec0ac4da20995265f91c8.diff
LOG: [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
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/sizeless-1.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 152d177f147b..373ae9752d41 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7586,6 +7586,11 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
/*IsIntFirstExpr=*/false))
return LHSTy;
+ // Allow ?: operations in which both operands have the same
+ // built-in sizeless type.
+ if (LHSTy->isSizelessBuiltinType() && LHSTy == RHSTy)
+ return LHSTy;
+
// Emit a better diagnostic if one of the expressions is a null pointer
// constant and the other is not a pointer type. In this case, the user most
// likely forgot to take the address of the other expression.
diff --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c
index c823823fa00c..a2ac9075347d 100644
--- a/clang/test/Sema/sizeless-1.c
+++ b/clang/test/Sema/sizeless-1.c
@@ -126,6 +126,11 @@ void func(int sel) {
const_volatile_int8 = local_int8; // expected-error {{cannot assign to variable 'const_volatile_int8' with const-qualified type 'const volatile svint8_t'}}
+ init_int8 = sel ? init_int8 : local_int8;
+ init_int8 = sel ? init_int8 : const_int8;
+ init_int8 = sel ? volatile_int8 : const_int8;
+ init_int8 = sel ? volatile_int8 : const_volatile_int8;
+
pass_int8(local_int8);
pass_int8(local_int16); // expected-error {{passing 'svint16_t' (aka '__SVInt16_t') to parameter of incompatible type 'svint8_t'}}
More information about the cfe-commits
mailing list