Skip to content

Commit 1dd104d

Browse files
committed
[clang][Interp] Implement _Complex Not unary operators
This only happens in C as far as I can tell. The complex varialbe will have undergone a conversion to bool in C++ before reaching the unary operator.
1 parent 1d900e2 commit 1dd104d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,17 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
31823182
case UO_AddrOf:
31833183
return this->delegate(SubExpr);
31843184

3185+
case UO_LNot:
3186+
if (!this->visit(SubExpr))
3187+
return false;
3188+
if (!this->emitComplexBoolCast(SubExpr))
3189+
return false;
3190+
if (!this->emitInvBool(E))
3191+
return false;
3192+
if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
3193+
return this->emitCast(PT_Bool, ET, E);
3194+
return true;
3195+
31853196
case UO_Real:
31863197
return this->emitComplexReal(SubExpr);
31873198

clang/test/AST/Interp/complex.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ void blah() {
1414
_Static_assert((0.0 + 0.0j) == (0.0 + 0.0j), "");
1515
_Static_assert((0.0 + 0.0j) != (0.0 + 0.0j), ""); // both-error {{static assertion}} \
1616
// both-note {{evaluates to}}
17+
18+
const _Complex float FC = {0.0f, 0.0f};
19+
_Static_assert(!FC, "");
20+
const _Complex float FI = {0, 0};
21+
_Static_assert(!FI, "");

0 commit comments

Comments
 (0)