Skip to content

Commit cb8e936

Browse files
committed
[clang][Interp] Implement ~ operator for complex values
1 parent 2f4ebf8 commit cb8e936

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,18 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
38273827
// we sometimes have to do the lvalue-to-rvalue conversion here manually.
38283828
return this->emitArrayElemPop(classifyPrim(E->getType()), 1, E);
38293829

3830+
case UO_Not: // ~x
3831+
if (!this->visit(SubExpr))
3832+
return false;
3833+
// Negate the imaginary component.
3834+
if (!this->emitArrayElem(ElemT, 1, E))
3835+
return false;
3836+
if (!this->emitNeg(ElemT, E))
3837+
return false;
3838+
if (!this->emitInitElem(ElemT, 1, E))
3839+
return false;
3840+
return DiscardResult ? this->emitPopPtr(E) : true;
3841+
38303842
default:
38313843
return this->emitInvalid(E);
38323844
}

clang/test/AST/Interp/complex.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ static_assert(__imag(Doubles[2]) == 0.0, "");
115115
static_assert(__real(Doubles[3]) == 0.0, "");
116116
static_assert(__imag(Doubles[3]) == 0.0, "");
117117

118+
static_assert(~(0.5 + 1.5j) == (0.5 + -1.5j), "");
119+
118120
void func(void) {
119121
__complex__ int arr;
120122
_Complex int result;

0 commit comments

Comments
 (0)