diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index efa98c6517a2e..a4a00ddab6503 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -672,18 +672,28 @@ bool ByteCodeExprGen::VisitInitListExpr(const InitListExpr *E) { } if (T->isAnyComplexType()) { - unsigned InitIndex = 0; - for (const Expr *Init : E->inits()) { - PrimType InitT = classifyPrim(Init->getType()); - - if (!this->visit(Init)) - return false; + unsigned NumInits = E->getNumInits(); + QualType ElemQT = E->getType()->getAs()->getElementType(); + PrimType ElemT = classifyPrim(ElemQT); + if (NumInits == 0) { + // Zero-initialize both elements. + for (unsigned I = 0; I < 2; ++I) { + if (!this->visitZeroInitializer(ElemT, ElemQT, E)) + return false; + if (!this->emitInitElem(ElemT, I, E)) + return false; + } + } else if (NumInits == 2) { + unsigned InitIndex = 0; + for (const Expr *Init : E->inits()) { + if (!this->visit(Init)) + return false; - if (!this->emitInitElem(InitT, InitIndex, E)) - return false; - ++InitIndex; + if (!this->emitInitElem(ElemT, InitIndex, E)) + return false; + ++InitIndex; + } } - assert(InitIndex == 2); return true; } diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp index 4fd2b5cfd7364..ba9fcd39fdd77 100644 --- a/clang/test/AST/Interp/complex.cpp +++ b/clang/test/AST/Interp/complex.cpp @@ -29,5 +29,28 @@ static_assert(__real(I1) == 1, ""); static_assert(__imag(I1) == 2, ""); +constexpr _Complex double D1 = {}; +static_assert(__real(D1) == 0, ""); +static_assert(__imag(D1) == 0, ""); + +constexpr _Complex int I2 = {}; +static_assert(__real(I2) == 0, ""); +static_assert(__imag(I2) == 0, ""); + + +#if 0 +/// FIXME: This should work in the new interpreter. +constexpr _Complex double D2 = {12}; +static_assert(__real(D2) == 12, ""); +static_assert(__imag(D2) == 12, ""); + +constexpr _Complex int I3 = {15}; +static_assert(__real(I3) == 15, ""); +static_assert(__imag(I3) == 15, ""); +#endif + + + + /// FIXME: This should work in the new interpreter as well. // constexpr _Complex _BitInt(8) A = 0;// = {4};