[PATCH] D150654: [clang][Interp] ComplexFloatingToBoolean casts

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 16 03:06:19 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150654

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/complex.cpp


Index: clang/test/AST/Interp/complex.cpp
===================================================================
--- clang/test/AST/Interp/complex.cpp
+++ clang/test/AST/Interp/complex.cpp
@@ -66,4 +66,11 @@
   static_assert(F5, "");
   constexpr _Complex unsigned char F6 = {0, 0};
   static_assert(!F6, "");
+
+  constexpr _Complex float F7 = {0, 1};
+  static_assert(F7, "");
+  constexpr _Complex float F8 = {1, 0};
+  static_assert(F8, "");
+  constexpr _Complex double F9 = {0, 0};
+  static_assert(!F9, "");
 }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -231,7 +231,8 @@
     return this->emitNEPtr(CE);
   }
 
-  case CK_IntegralComplexToBoolean: {
+  case CK_IntegralComplexToBoolean:
+  case CK_FloatingComplexToBoolean: {
     std::optional<PrimType> ElemT =
         classifyComplexElementType(SubExpr->getType());
     if (!ElemT)
@@ -246,8 +247,14 @@
       return false;
     if (!this->emitLoadPop(*ElemT, CE))
       return false;
-    if (!this->emitCast(*ElemT, PT_Bool, CE))
-      return false;
+    if (*ElemT == PT_Float) {
+      if (!this->emitCastFloatingIntegral(PT_Bool, CE))
+        return false;
+    } else {
+      if (!this->emitCast(*ElemT, PT_Bool, CE))
+        return false;
+    }
+
     // We now have the bool value of E[0] on the stack.
     LabelTy LabelTrue = this->getLabel();
     if (!this->jumpTrue(LabelTrue))
@@ -259,8 +266,13 @@
       return false;
     if (!this->emitLoadPop(*ElemT, CE))
       return false;
-    if (!this->emitCast(*ElemT, PT_Bool, CE))
-      return false;
+    if (*ElemT == PT_Float) {
+      if (!this->emitCastFloatingIntegral(PT_Bool, CE))
+        return false;
+    } else {
+      if (!this->emitCast(*ElemT, PT_Bool, CE))
+        return false;
+    }
     // Leave the boolean value of E[1] on the stack.
     LabelTy EndLabel = this->getLabel();
     this->jump(EndLabel);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150654.522515.patch
Type: text/x-patch
Size: 2020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230516/b0028be9/attachment.bin>


More information about the cfe-commits mailing list