This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: new __builtin_choose_type (patch)


On Tue, 2001-10-02 at 21:54, Geoff Keating wrote:
> Aldy Hernandez <aldyh@redhat.com> writes:
> 
> > btw, i can't get my builtin to return a given object (irregardless of
> > it's type) because the way builtins work seems to force me to choose a
> > return value type.  i don't want a specific value type.  i want
> > something generic.  see code documentation below.
> 
> What does va_arg do?

__builtin_next_arg returns a pointer to the next argument, obviously
only working on stack arguments.

if we were to follow a similar approach (have the builtin return a void
pointer), we could do:

    float floatt;
    float  f1, f2, f3;
    
    f2 = *((float *)__builtin_choose_type (f1, floatt, f3, etc)
    
    /* f1 and floatt are of the same type, so eval and return f3 */
    
in theory, the builtin would return the address of "f3" as a void*.  we
could then cast that to the appropriate type.  However, this will only
work with lvalues (since they're the only ones with addresses :-)).  and
will definitely not work with "f3" being a function call.

perhaps, the whole builtin mechanism needs to be hacked for it to return
anonymous types.

IMO, this builtin return type needs to be calculated before
expand_builtin().  we could put in a hook when we're calling the builtin
to calculate and set the appropriate return type.  this way the rest of
the FE can do proper type checking.

ok, so it sounds a bit complicated, but it's pretty clear in my head
:).  i'll come up with a patch to demonstrate  later today.  but if
anyone has a better idea on how to implement anonymous return types in
builtins, feel free to chime in.

-- 
Aldy Hernandez					E-mail: aldyh@redhat.com
Professional Gypsy on a Motorcycle
Red Hat, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]