tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
If the argument is of composite type, we need a pointer to return. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155710 Files: clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/test/AST/Interp/records.cpp Index: clang/test/AST/Interp/records.cpp =================================================================== --- clang/test/AST/Interp/records.cpp +++ clang/test/AST/Interp/records.cpp @@ -879,3 +879,27 @@ } } +namespace CompositeDefaultArgs { + struct Foo { + int a; + int b; + constexpr Foo() : a(12), b(13) {} + }; + + class Bar { + public: + bool B = false; + + constexpr int someFunc(Foo F = Foo()) { + this->B = true; + return 5; + } + }; + + constexpr bool testMe() { + Bar B; + B.someFunc(); + return B.B; + } + static_assert(testMe(), ""); +} Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2105,7 +2105,18 @@ template <class Emitter> bool ByteCodeExprGen<Emitter>::VisitCXXDefaultArgExpr( const CXXDefaultArgExpr *E) { - return this->visit(E->getExpr()); + const Expr *SubExpr = E->getExpr(); + + if (std::optional<PrimType> T = classify(E->getExpr())) + return this->visit(SubExpr); + + if (std::optional<unsigned> LocalIndex = + allocateLocal(SubExpr, /*IsExtended=*/true)) { + if (!this->emitGetPtrLocal(*LocalIndex, E)) + return false; + return this->visitInitializer(SubExpr); + } + return false; } template <class Emitter>
Index: clang/test/AST/Interp/records.cpp =================================================================== --- clang/test/AST/Interp/records.cpp +++ clang/test/AST/Interp/records.cpp @@ -879,3 +879,27 @@ } } +namespace CompositeDefaultArgs { + struct Foo { + int a; + int b; + constexpr Foo() : a(12), b(13) {} + }; + + class Bar { + public: + bool B = false; + + constexpr int someFunc(Foo F = Foo()) { + this->B = true; + return 5; + } + }; + + constexpr bool testMe() { + Bar B; + B.someFunc(); + return B.B; + } + static_assert(testMe(), ""); +} Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2105,7 +2105,18 @@ template <class Emitter> bool ByteCodeExprGen<Emitter>::VisitCXXDefaultArgExpr( const CXXDefaultArgExpr *E) { - return this->visit(E->getExpr()); + const Expr *SubExpr = E->getExpr(); + + if (std::optional<PrimType> T = classify(E->getExpr())) + return this->visit(SubExpr); + + if (std::optional<unsigned> LocalIndex = + allocateLocal(SubExpr, /*IsExtended=*/true)) { + if (!this->emitGetPtrLocal(*LocalIndex, E)) + return false; + return this->visitInitializer(SubExpr); + } + return false; } template <class Emitter>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits