Skip to content

Commit

Permalink
[clang][Interp] Support __real/__imag on primitives (#75485)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jan 15, 2024
1 parent 5ccf19d commit 12e425d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,8 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
return false;
return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
case UO_Real: { // __real x
assert(!T);
if (T)
return this->delegate(SubExpr);
if (!this->visit(SubExpr))
return false;
if (!this->emitConstUint8(0, E))
Expand All @@ -2783,7 +2784,11 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
return true;
}
case UO_Imag: { // __imag x
assert(!T);
if (T) {
if (!this->discard(SubExpr))
return false;
return this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr);
}
if (!this->visit(SubExpr))
return false;
if (!this->emitConstUint8(1, E))
Expand Down
6 changes: 6 additions & 0 deletions clang/test/AST/Interp/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ constexpr _Complex int I2 = {};
static_assert(__real(I2) == 0, "");
static_assert(__imag(I2) == 0, "");

static_assert(__real(4.0) == 4.0, "");
static_assert(__real(12u) == 12u, "");
static_assert(__imag(4.0) == 0.0, "");
static_assert(__imag(13) == 0, "");



/// Standalone complex expressions.
static_assert(__real((_Complex float){1.0, 3.0}) == 1.0, "");
Expand Down

0 comments on commit 12e425d

Please sign in to comment.