Skip to content

Commit 2a17357

Browse files
kito-chengjrtc27
andcommitted
Clarify address of struct return value is not required to be returned
The psABI didn't specify whether the address should be returned or not. GCC and LLVM are implemented differently here; GCC will return the address in a0, but LLVM won't due to it not being specified. It's a potential ABI incompatible change for GCC, but fortunately GCC doesn't rely on that behavior and will rematerialise the address rather than using the value of a0. The following code can demonstrate this issue: ``` struct int4 { int values[4]; }; struct int4 i4a; struct int4 foo (struct int4 arg1) { asm volatile ("li a0, 100 #force clobber a0":::"a0"); return arg1; } ``` Fixes #238 Co-authored-by: Jessica Clarke <[email protected]>
1 parent 4969a01 commit 2a17357

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

riscv-cc.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ type would be passed. If such an argument would have been passed by
155155
reference, the caller allocates memory for the return value, and passes the
156156
address as an implicit first parameter.
157157

158+
NOTE: There is no requirement that the address be returned from the function
159+
and so software should not assume that a0 will hold the address of the return
160+
value on return.
161+
158162
The stack grows downwards (towards lower addresses) and the stack pointer shall
159163
be aligned to a 128-bit boundary upon procedure entry.
160164
The first argument passed on the stack is located at offset zero of the stack pointer

0 commit comments

Comments
 (0)