tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
We reach visitExpr() when evaluating standalone expressions. However, the RetValue() code path was unused before, because we never reach it, even with structs or arrays. RetValue expects a pointer on the stack it can take apart to return an APValue, so provide it with one. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150661 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/complex.cpp Index: clang/test/AST/Interp/complex.cpp =================================================================== --- clang/test/AST/Interp/complex.cpp +++ clang/test/AST/Interp/complex.cpp @@ -38,6 +38,10 @@ static_assert(__imag(I2) == 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}; Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1887,9 +1887,16 @@ // Expressions with a composite return type. // For us, that means everything we don't // have a PrimType for. - if (!visit(E)) - return false; - return this->emitRetValue(E); + if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) { + if (!this->visitLocalInitializer(E, *LocalOffset)) + return false; + + if (!this->emitGetPtrLocal(*LocalOffset, E)) + return false; + return this->emitRetValue(E); + } + + return false; } /// Toplevel visitDecl().
Index: clang/test/AST/Interp/complex.cpp =================================================================== --- clang/test/AST/Interp/complex.cpp +++ clang/test/AST/Interp/complex.cpp @@ -38,6 +38,10 @@ static_assert(__imag(I2) == 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}; Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1887,9 +1887,16 @@ // Expressions with a composite return type. // For us, that means everything we don't // have a PrimType for. - if (!visit(E)) - return false; - return this->emitRetValue(E); + if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) { + if (!this->visitLocalInitializer(E, *LocalOffset)) + return false; + + if (!this->emitGetPtrLocal(*LocalOffset, E)) + return false; + return this->emitRetValue(E); + } + + return false; } /// Toplevel visitDecl().
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits