Author: Timm Bäder Date: 2023-12-14T13:17:40+01:00 New Revision: 935f5ee9c9fd6ff358b07fb4ff8e21b77c1a5ce8
URL: https://github.com/llvm/llvm-project/commit/935f5ee9c9fd6ff358b07fb4ff8e21b77c1a5ce8 DIFF: https://github.com/llvm/llvm-project/commit/935f5ee9c9fd6ff358b07fb4ff8e21b77c1a5ce8.diff LOG: [clang][Interp] ComplexFloatingToBoolean casts Differential Revision: https://reviews.llvm.org/D150654 Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/complex.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index c428446386c04b..fdc84d0a0da005 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -222,7 +222,8 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) { return this->emitNE(PtrT, CE); } - case CK_IntegralComplexToBoolean: { + case CK_IntegralComplexToBoolean: + case CK_FloatingComplexToBoolean: { std::optional<PrimType> ElemT = classifyComplexElementType(SubExpr->getType()); if (!ElemT) @@ -237,8 +238,14 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) { 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)) @@ -250,8 +257,13 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) { 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); diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp index dbdbc2f7356e6b..084a63d4701c23 100644 --- a/clang/test/AST/Interp/complex.cpp +++ b/clang/test/AST/Interp/complex.cpp @@ -66,4 +66,11 @@ namespace CastToBool { 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, ""); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits