[PATCH 10/11] ELFv2 ABI: structure passing / return

Joel Brobecker brobecker@adacore.com
Fri Jan 31 10:09:00 GMT 2014


> So I've chosen those types deliberately :-)  In ppc64_aggregate_candidate
> we find *any* aggregate as long as all members are of the same type.  It
> is theoretically possible that the number of such members exceed 2G, e.g.
> if the aggregate is a very large array.  Thus the obvious return type is
> the type we use for array indices, i.e. LONGEST.
> 
> However, in ppc64_elfv2_abi_homogeneous_aggregate we only ever set n_elts
> if the aggregate is one that is to be returned in registers, which means
> that the number of members can never exceed 8.  Thus the obvious type of
> n_elts is int.
> 
> Note that the cast is guaranteed to be safe, since the value is bounds-
> checked before:
> 
> +      if (field_count > 0)
> [...]
> +         if (field_count * n_regs <= 8)
> [...]
> +               *n_elts = (int) field_count;
> 
> Given the above, it seems best to me to chose types as I did orignally ...

That is indeed a good explanation. I suggest we re-use your explanation,
or at least the second part of it, to explain why n_elts is an int
and why the cast of field_count down to int is safe. You'll avoid
someone like me, who is tuned to treat all casts as suspicious, from
unmaking your choice :-).

-- 
Joel



More information about the Gdb-patches mailing list