Author: Timm Bäder Date: 2024-02-26T11:40:58+01:00 New Revision: a5ccf8522b96c56fc6bda54cf68a64c5d65b75cb
URL: https://github.com/llvm/llvm-project/commit/a5ccf8522b96c56fc6bda54cf68a64c5d65b75cb DIFF: https://github.com/llvm/llvm-project/commit/a5ccf8522b96c56fc6bda54cf68a64c5d65b75cb.diff LOG: [clang][Interp] Not all RVO call expressions are initializing We do not necessarily prepare storage for the return value when we are returning a complex value. Added: Modified: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/complex.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 49ba8e95f17995..b5402ec8caaec6 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2703,7 +2703,14 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) { return false; } } else { - assert(Initializing); + // We need the result. Prepare a pointer to return or + // dup the current one. + if (!Initializing) { + if (std::optional<unsigned> LocalIndex = allocateLocal(E)) { + if (!this->emitGetPtrLocal(*LocalIndex, E)) + return false; + } + } if (!this->emitDupPtr(E)) return false; } diff --git a/clang/test/AST/Interp/complex.cpp b/clang/test/AST/Interp/complex.cpp index 2b65ccf9946e70..b6091d90867a01 100644 --- a/clang/test/AST/Interp/complex.cpp +++ b/clang/test/AST/Interp/complex.cpp @@ -124,6 +124,12 @@ void func(void) { result = arr * ii; } +constexpr _Complex float getComplexFloat() { + return {1,2}; +} +static_assert(__real(getComplexFloat()) == 1, ""); +static_assert(__imag(getComplexFloat()) == 2, ""); + namespace CastToBool { constexpr _Complex int F = {0, 1}; static_assert(F, ""); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits