[clang] fcf8827 - [Sema][RISCV][SVE] Allow ?: to select Typedef BuiltinType in C
ShihPo Hung via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 4 00:33:37 PDT 2021
Author: ShihPo Hung
Date: 2021-06-04T15:33:14+08:00
New Revision: fcf8827a98beb1f8baea883451508d9cd91f57bc
URL: https://github.com/llvm/llvm-project/commit/fcf8827a98beb1f8baea883451508d9cd91f57bc
DIFF: https://github.com/llvm/llvm-project/commit/fcf8827a98beb1f8baea883451508d9cd91f57bc.diff
LOG: [Sema][RISCV][SVE] Allow ?: to select Typedef BuiltinType in C
This patch solves an error such as:
incompatible operand types ('vbool4_t' (aka '__rvv_bool4_t') and '__rvv_bool4_t')
when one of the value is a TypedefType of the other value in ?:.
Reviewed By: rjmccall
Differential Revision: https://reviews.llvm.org/D103603
Added:
Modified:
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/riscv-types.c
clang/test/Sema/sizeless-1.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ba38b1089413f..422eddce86cd8 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8393,7 +8393,7 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
// Allow ?: operations in which both operands have the same
// built-in sizeless type.
- if (LHSTy->isSizelessBuiltinType() && LHSTy == RHSTy)
+ if (LHSTy->isSizelessBuiltinType() && Context.hasSameType(LHSTy, RHSTy))
return LHSTy;
// Emit a better diagnostic if one of the expressions is a null pointer
diff --git a/clang/test/Sema/riscv-types.c b/clang/test/Sema/riscv-types.c
index f1bf2e6afecde..0d09546603b66 100644
--- a/clang/test/Sema/riscv-types.c
+++ b/clang/test/Sema/riscv-types.c
@@ -134,3 +134,12 @@ void bar(void) {
// CHECK: __rvv_int8mf2_t x43;
__rvv_int8mf2_t x43;
}
+
+typedef __rvv_bool4_t vbool4_t;
+__rvv_bool4_t get_rvv_bool4();
+vbool4_t get_vbool4_t();
+
+void func1(int sel) {
+ // CHECK: vbool4_t t0 = sel ? get_rvv_bool4() : get_vbool4_t();
+ vbool4_t t0 = sel ? get_rvv_bool4() : get_vbool4_t();
+}
diff --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c
index e1d9265448947..a8c08731d53e6 100644
--- a/clang/test/Sema/sizeless-1.c
+++ b/clang/test/Sema/sizeless-1.c
@@ -57,6 +57,7 @@ void func(int sel) {
static svint8_t static_int8; // expected-error {{non-local variable with sizeless type 'svint8_t'}}
svint8_t local_int8;
+ int8_typedef typedef_int8;
svint16_t local_int16;
svint8_t __attribute__((aligned)) aligned_int8_1; // expected-error {{'aligned' attribute cannot be applied to sizeless type 'svint8_t'}}
@@ -137,6 +138,7 @@ 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 : typedef_int8;
init_int8 = sel ? init_int8 : const_int8;
init_int8 = sel ? volatile_int8 : const_int8;
init_int8 = sel ? volatile_int8 : const_volatile_int8;
More information about the cfe-commits
mailing list