Skip to content

Commit

Permalink
[clang][Interp] Implement _Complex Not unary operators
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbaederr committed Mar 12, 2024
1 parent 1d900e2 commit 1dd104d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3182,6 +3182,17 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
case UO_AddrOf:
return this->delegate(SubExpr);

case UO_LNot:
if (!this->visit(SubExpr))
return false;
if (!this->emitComplexBoolCast(SubExpr))
return false;
if (!this->emitInvBool(E))
return false;
if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
return this->emitCast(PT_Bool, ET, E);
return true;

case UO_Real:
return this->emitComplexReal(SubExpr);

Expand Down
5 changes: 5 additions & 0 deletions clang/test/AST/Interp/complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ void blah() {
_Static_assert((0.0 + 0.0j) == (0.0 + 0.0j), "");
_Static_assert((0.0 + 0.0j) != (0.0 + 0.0j), ""); // both-error {{static assertion}} \
// both-note {{evaluates to}}

const _Complex float FC = {0.0f, 0.0f};
_Static_assert(!FC, "");
const _Complex float FI = {0, 0};
_Static_assert(!FI, "");

0 comments on commit 1dd104d

Please sign in to comment.