Made struct assignment less hackish.

This commit is contained in:
acqn
2020-08-20 07:56:11 +08:00
committed by Oliver Schmidt
parent d1995fc81a
commit c3a6b39945

View File

@@ -95,10 +95,13 @@ static int CopyStruct (ExprDesc* LExpr, ExprDesc* RExpr)
/* Store it into the location referred in the primary */ /* Store it into the location referred in the primary */
Store (LExpr, stype); Store (LExpr, stype);
/* Value is in primary as an rvalue */
ED_FinalizeRValLoad (LExpr);
} else { } else {
/* The only way this can happen is in chained assignments */ /* The rhs cannot happen to be loaded in the primary as it is too big */
if (!ED_IsLocPrimary (RExpr)) { if (!ED_IsLocExpr (RExpr)) {
ED_AddrExpr (RExpr); ED_AddrExpr (RExpr);
LoadExpr (CF_NONE, RExpr); LoadExpr (CF_NONE, RExpr);
} }
@@ -112,16 +115,19 @@ static int CopyStruct (ExprDesc* LExpr, ExprDesc* RExpr)
/* Call the memcpy function */ /* Call the memcpy function */
g_call (CF_FIXARGC, Func_memcpy, 4); g_call (CF_FIXARGC, Func_memcpy, 4);
/* The result is an rvalue referenced in the primary */
ED_FinalizeRValLoad (LExpr);
/* Restore the indirection level of lhs */ /* Restore the indirection level of lhs */
ED_IndExpr (LExpr); ED_IndExpr (LExpr);
/* Clear the tested flag set during loading. This is not neccessary
** currently (and probably ever) as a struct/union cannot be converted
** to a boolean in C, but there is no harm to be future-proof.
*/
ED_MarkAsUntested (LExpr);
} }
/* Clear the tested flag set during loading. This is not neccessary
** currently (and probably ever) as a struct/union cannot be converted
** to a boolean in C, but there is no harm to be future-proof.
*/
ED_MarkAsUntested (LExpr);
return 1; return 1;
} }
@@ -247,6 +253,9 @@ void Assignment (ExprDesc* Expr)
/* Restore the expression type */ /* Restore the expression type */
Expr->Type = ltype; Expr->Type = ltype;
/* Value is in primary as an rvalue */
ED_FinalizeRValLoad (Expr);
} else { } else {
/* Get the address on stack if needed */ /* Get the address on stack if needed */
@@ -264,8 +273,8 @@ void Assignment (ExprDesc* Expr)
/* Generate a store instruction */ /* Generate a store instruction */
Store (Expr, 0); Store (Expr, 0);
} /* Value is in primary as an rvalue */
ED_FinalizeRValLoad (Expr);
/* Value might be still in primary and not an lvalue */ }
ED_FinalizeRValLoad (Expr);
} }