Skip to content

Commit 28b8207

Browse files
committed
[clang][Interp] Support ImplicitValueInitExpr for complex types
Initialize both elements to 0, once again.
1 parent 8c84096 commit 28b8207

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,19 @@ bool ByteCodeExprGen<Emitter>::VisitImplicitValueInitExpr(const ImplicitValueIni
820820
return true;
821821
}
822822

823+
if (QT->isAnyComplexType()) {
824+
assert(Initializing);
825+
QualType ElemQT = QT->getAs<ComplexType>()->getElementType();
826+
PrimType ElemT = classifyPrim(ElemQT);
827+
for (unsigned I = 0; I < 2; ++I) {
828+
if (!this->visitZeroInitializer(ElemT, ElemQT, E))
829+
return false;
830+
if (!this->emitInitElem(ElemT, I, E))
831+
return false;
832+
}
833+
return true;
834+
}
835+
823836
return false;
824837
}
825838

clang/test/AST/Interp/complex.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ static_assert(__imag(I3) == 0, "");
102102
// constexpr _Complex _BitInt(8) A = 0;// = {4};
103103

104104

105+
constexpr _Complex double Doubles[4] = {{1.0, 2.0}};
106+
static_assert(__real(Doubles[0]) == 1.0, "");
107+
static_assert(__imag(Doubles[0]) == 2.0, "");
108+
static_assert(__real(Doubles[1]) == 0.0, "");
109+
static_assert(__imag(Doubles[1]) == 0.0, "");
110+
static_assert(__real(Doubles[2]) == 0.0, "");
111+
static_assert(__imag(Doubles[2]) == 0.0, "");
112+
static_assert(__real(Doubles[3]) == 0.0, "");
113+
static_assert(__imag(Doubles[3]) == 0.0, "");
114+
105115
void func(void) {
106116
__complex__ int arr;
107117
_Complex int result;

0 commit comments

Comments
 (0)