@@ -4676,7 +4676,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
46764676 OCE && OCE->isAssignmentOp ()) {
46774677 // Just like with regular assignments, we need to special-case assignment
46784678 // operators here and evaluate the RHS (the second arg) before the LHS (the
4679- // first arg. We fix this by using a Flip op later.
4679+ // first arg) . We fix this by using a Flip op later.
46804680 assert (Args.size () == 2 );
46814681 IsAssignmentOperatorCall = true ;
46824682 std::reverse (Args.begin (), Args.end ());
@@ -5664,6 +5664,21 @@ bool Compiler<Emitter>::compileDestructor(const CXXDestructorDecl *Dtor) {
56645664 return this ->emitPopPtr (Dtor) && this ->emitRetVoid (Dtor);
56655665}
56665666
5667+ template <class Emitter >
5668+ bool Compiler<Emitter>::compileUnionCopyAssignmentOperator(
5669+ const CXXMethodDecl *MD) {
5670+ if (!this ->emitThis (MD))
5671+ return false ;
5672+
5673+ auto PVD = MD->getParamDecl (0 );
5674+ ParamOffset PO = this ->Params [PVD]; // Must exist.
5675+
5676+ if (!this ->emitGetParam (PT_Ptr, PO.Offset , MD))
5677+ return false ;
5678+
5679+ return this ->emitMemcpy (MD) && this ->emitRet (PT_Ptr, MD);
5680+ }
5681+
56675682template <class Emitter >
56685683bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
56695684 // Classify the return type.
@@ -5675,9 +5690,15 @@ bool Compiler<Emitter>::visitFunc(const FunctionDecl *F) {
56755690 return this ->compileDestructor (Dtor);
56765691
56775692 // Emit custom code if this is a lambda static invoker.
5678- if (const auto *MD = dyn_cast<CXXMethodDecl>(F);
5679- MD && MD->isLambdaStaticInvoker ())
5680- return this ->emitLambdaStaticInvokerBody (MD);
5693+ if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
5694+ const RecordDecl *RD = MD->getParent ();
5695+
5696+ if (RD->isUnion () && MD->isCopyAssignmentOperator ())
5697+ return this ->compileUnionCopyAssignmentOperator (MD);
5698+
5699+ if (MD->isLambdaStaticInvoker ())
5700+ return this ->emitLambdaStaticInvokerBody (MD);
5701+ }
56815702
56825703 // Regular functions.
56835704 if (const auto *Body = F->getBody ())
0 commit comments