This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 10/11] ELFv2 ABI: structure passing / return
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: brobecker at adacore dot com (Joel Brobecker)
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 29 Jan 2014 19:14:28 +0100 (CET)
- Subject: Re: [PATCH 10/11] ELFv2 ABI: structure passing / return
- Authentication-results: sourceware.org; auth=none
Joel Brobecker wrote:
> > +/* Walk down the type tree of TYPE counting consecutive base elements.
> > + If *FIELD_TYPE is NULL, then set it to the first valid floating point
> > + or vector type. If a non-floating point or vector type is found, or
> > + if a floating point or vector type that doesn't match a non-NULL
> > + *FIELD_TYPE is found, then return -1, otherwise return the count in the
> > + sub-tree. */
> > +
> > +static LONGEST
> > +ppc64_aggregate_candidate (struct type *type,
> > + struct type **field_type)
>
> I think we can reasonably change the return type to int, here?
> That would avoid the cast you're making at:
>
> > + struct type *field_type = NULL;
> > + LONGEST field_count = ppc64_aggregate_candidate (type, &field_type);
> [...]
> > + if (n_elts)
> > + *n_elts = (int) field_count;
>
> The other option is to make everything use LONGEST for this count.
> That way, everything would be consistent and we'd be avoiding a cast
> as well.
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 ...
Bye,
Ulrich
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com