llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> --- Full diff: https://github.com/llvm/llvm-project/pull/75590.diff 2 Files Affected: - (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+26) - (modified) clang/test/AST/Interp/complex.cpp (+4-5) ``````````diff diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index d0980882f402b9..d7e1f3d3a3872a 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -283,6 +283,28 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) { case CK_ToVoid: return discard(SubExpr); + case CK_IntegralRealToComplex: + case CK_FloatingRealToComplex: { + // We're creating a complex value here, so need to + // allocate storage for it. + if (!Initializing) { + std::optional<unsigned> LocalIndex = + allocateLocal(CE, /*IsExtended=*/true); + if (!LocalIndex) + return false; + if (!this->emitGetPtrLocal(*LocalIndex, CE)) + return false; + } + + if (!this->visitArrayElemInit(0, SubExpr)) + return false; + // Zero-init the second element. + PrimType T = classifyPrim(SubExpr->getType()); + if (!this->visitZeroInitializer(T, SubExpr->getType(), SubExpr)) + return false; + return this->emitInitElem(T, 1, SubExpr); + } + default: assert(false && "Cast not implemented"); } @@ -835,6 +857,10 @@ bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) { if (T->isAnyComplexType()) { unsigned NumInits = E->getNumInits(); + + if (NumInits == 1) + return this->delegate(E->inits()[0]); + QualType ElemQT = E->getType()->getAs<ComplexType>()->getElementType(); PrimType ElemT = classifyPrim(ElemQT); if (NumInits == 0) { diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp index 66490e973988bb..bf340d6e3ff68a 100644 --- a/clang/test/AST/Interp/complex.cpp +++ b/clang/test/AST/Interp/complex.cpp @@ -37,21 +37,20 @@ constexpr _Complex int I2 = {}; static_assert(__real(I2) == 0, ""); static_assert(__imag(I2) == 0, ""); +static_assert(__real((_Complex unsigned)5) == 5); +static_assert(__imag((_Complex unsigned)5) == 0); /// Standalone complex expressions. static_assert(__real((_Complex float){1.0, 3.0}) == 1.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, ""); +static_assert(__imag(D2) == 0, ""); constexpr _Complex int I3 = {15}; static_assert(__real(I3) == 15, ""); -static_assert(__imag(I3) == 15, ""); -#endif +static_assert(__imag(I3) == 0, ""); /// FIXME: This should work in the new interpreter as well. // constexpr _Complex _BitInt(8) A = 0;// = {4}; `````````` </details> https://github.com/llvm/llvm-project/pull/75590 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits