Skip to content

Commit c0fbd21

Browse files
authored
Merge pull request #365 from riscv-non-isa/fix-358
Add note for array with empty struct or union
2 parents cfed71f + dcb116f commit c0fbd21

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

riscv-cc.adoc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,27 @@ hierarchy flattened, including any array fields. That is, `struct { struct
270270
{ float f[1]; } a[2]; }` and `struct { float f0; float f1; }` are
271271
treated the same. Fields containing empty structs or unions are ignored while
272272
flattening, even in {Cpp}, unless they have nontrivial copy constructors or
273-
destructors. Fields containing zero-length bit-fields are ignored while
274-
flattening. Attributes such as `aligned` or `packed` do not interfere with a
275-
struct's eligibility for being passed in registers according to the rules
276-
below, i.e. `struct { int i; double d; }` and `+struct
273+
destructors. Fields containing zero-length bit-fields or zero-length arrays are
274+
ignored while flattening. Attributes such as `aligned` or `packed` do not
275+
interfere with a struct's eligibility for being passed in registers according
276+
to the rules below, i.e. `struct { int i; double d; }` and `+struct
277277
__attribute__((__packed__)) { int i; double d }+` are treated the same, as are
278278
`struct { float f; float g; }` and `+struct { float f; float g __attribute__
279279
((aligned (8))); }+`.
280280

281+
NOTE: One exceptional case for the flattening rule is an array of empty
282+
structs or unions; C treats it as an empty field, but {Cpp}
283+
treats it as a non-empty field since {Cpp} defines the size of an empty struct
284+
or union as 1. i.e. for `struct { struct {} e[1]; float f; }` as the first
285+
argument, C will treat it like `struct { float f; }` and pass `f` in `fa0` as
286+
described below, whereas {Cpp} will pass the pass the entire aggregate in `a0`
287+
(XLEN = 64) or `a0` and `a1` (XLEN = 32), as described in the integer calling
288+
convention.
289+
Zero-length arrays of empty structs or union will be
290+
ignored for both C and {Cpp}. i.e. For `struct { struct {} e[0]; float f; };`,
291+
as the first argument, C and {Cpp} will treat it like `struct { float f; }`
292+
and pass `f` in `fa0` as described below.
293+
281294
A real floating-point argument is passed in a floating-point argument
282295
register if it is no more than ABI_FLEN bits wide and at least one floating-point
283296
argument register is available. Otherwise, it is passed according to the

0 commit comments

Comments
 (0)