> The ABI states that "Aggregates larger than 2×XLEN bits are passed by reference and are replaced in the argument list with the address" and "Arguments passed by reference may be modified by the callee."
>
>In the attached C test program, a struct bar with 3 ints is passed from main to foo. This struct is passed via the memory, and in order to protect struct bar from being modified within foo, a copy of bar needs to be made.
This is exactly the same for both small values and large ones.
The callee is free to modify registers used to pass arguments to it.
If the caller wants to preserve their original value then they need to
make a copy somewhere else. For optimised code this is usually in S
registers, but it can also be in memory i.e. on the stack.
It is exactly the same for large aggregates, except they can't fit in
to a register (or pair of registers). In memory is the only choice. If
the caller wants to use the original value of the aggregate again
after the call then it needs to make a copy, and pass the address of
either the copy or the original. If the caller doesn't need the
original value again after the call (which the callee can't possibly
know) then the caller can just pass the address of the original value.
Your student's compiler is wrong. If a standard function calls a
function compiled by them , the aggregate will be (harmlessly) copied
twice. But if the student's compiler calls a standard RISC-V function
... e.g. in the standard library ... then no one will copy the
aggregate, and disaster may follow. (If any such function exists ...
as far as I recall, all large structures are passed to the standard
library explicitly by reference anyway)
> --
> You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
sw-dev+un...@groups.riscv.org.
> To view this discussion on the web visit
https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/dc6fb0dc-02da-4c72-a334-f8419ebbff1en%40groups.riscv.org.