[PATCH] D103603: [Sema][RISCV] Allow ?: to select Typedef BuiltinType in C

ShihPo Hung via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 3 03:01:49 PDT 2021


arcbbb created this revision.
arcbbb added reviewers: rsandifo-arm, efriedma, sdesmalen, rovka, rjmccall, rengolin, HsiangKai, craig.topper.
Herald added subscribers: vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb.
arcbbb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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 ?:.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103603

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/riscv-types.c


Index: clang/test/Sema/riscv-types.c
===================================================================
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -134,3 +134,12 @@
   // 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();
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -8393,8 +8393,10 @@
 
   // Allow ?: operations in which both operands have the same
   // built-in sizeless type.
-  if (LHSTy->isSizelessBuiltinType() && LHSTy == RHSTy)
+  if (LHSTy->isSizelessBuiltinType() &&
+      (Context.getCanonicalType(LHSTy) == Context.getCanonicalType(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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103603.349505.patch
Type: text/x-patch
Size: 1143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210603/2b6877eb/attachment.bin>


More information about the cfe-commits mailing list