Skip to content

Commit 935f5ee

Browse files
committed
[clang][Interp] ComplexFloatingToBoolean casts
Differential Revision: https://reviews.llvm.org/D150654
1 parent 497480b commit 935f5ee

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
222222
return this->emitNE(PtrT, CE);
223223
}
224224

225-
case CK_IntegralComplexToBoolean: {
225+
case CK_IntegralComplexToBoolean:
226+
case CK_FloatingComplexToBoolean: {
226227
std::optional<PrimType> ElemT =
227228
classifyComplexElementType(SubExpr->getType());
228229
if (!ElemT)
@@ -237,8 +238,14 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
237238
return false;
238239
if (!this->emitLoadPop(*ElemT, CE))
239240
return false;
240-
if (!this->emitCast(*ElemT, PT_Bool, CE))
241-
return false;
241+
if (*ElemT == PT_Float) {
242+
if (!this->emitCastFloatingIntegral(PT_Bool, CE))
243+
return false;
244+
} else {
245+
if (!this->emitCast(*ElemT, PT_Bool, CE))
246+
return false;
247+
}
248+
242249
// We now have the bool value of E[0] on the stack.
243250
LabelTy LabelTrue = this->getLabel();
244251
if (!this->jumpTrue(LabelTrue))
@@ -250,8 +257,13 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
250257
return false;
251258
if (!this->emitLoadPop(*ElemT, CE))
252259
return false;
253-
if (!this->emitCast(*ElemT, PT_Bool, CE))
254-
return false;
260+
if (*ElemT == PT_Float) {
261+
if (!this->emitCastFloatingIntegral(PT_Bool, CE))
262+
return false;
263+
} else {
264+
if (!this->emitCast(*ElemT, PT_Bool, CE))
265+
return false;
266+
}
255267
// Leave the boolean value of E[1] on the stack.
256268
LabelTy EndLabel = this->getLabel();
257269
this->jump(EndLabel);

clang/test/AST/Interp/complex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,11 @@ namespace CastToBool {
6666
static_assert(F5, "");
6767
constexpr _Complex unsigned char F6 = {0, 0};
6868
static_assert(!F6, "");
69+
70+
constexpr _Complex float F7 = {0, 1};
71+
static_assert(F7, "");
72+
constexpr _Complex float F8 = {1, 0};
73+
static_assert(F8, "");
74+
constexpr _Complex double F9 = {0, 0};
75+
static_assert(!F9, "");
6976
}

0 commit comments

Comments
 (0)