[llvm-commits] [PATCH]: ppc32 va_arg() implementation
Roman Divacky
rdivacky at freebsd.org
Wed Jun 15 08:27:34 PDT 2011
On Tue, Jun 14, 2011 at 02:02:24PM -0700, Jim Grosbach wrote:
>
> On Jun 14, 2011, at 1:11 PM, Roman Divacky wrote:
>
> > On Tue, Jun 14, 2011 at 01:09:07PM -0700, Eli Friedman wrote:
> >> On Tue, Jun 14, 2011 at 1:02 PM, Roman Divacky <rdivacky at freebsd.org> wrote:
> >>> On Tue, Jun 14, 2011 at 12:59:18PM -0700, Eli Friedman wrote:
> >>>> On Tue, Jun 14, 2011 at 12:47 PM, Roman Divacky <rdivacky at freebsd.org> wrote:
> >>>>> Hi,
> >>>>>
> >>>>> the attached patch implements va_arg() lowering on ppc32.
> >>>>> Ints (8, 16, 32 and also 64 bits that need special treatment) work,
> >>>>> floats don't work (neither with gcc - we should warn when someone tries
> >>>>> to use them on ppc32 probably), doubles do work.
> >>>>
> >>>> It's impossible to make any C frontend generate a call to a varargs
> >>>> function that actually passes in something of type "float"... are you
> >>>> sure you're testing correctly?
> >>>
> >>> This is an example with doubles, to change it to floats you just
> >>> change the type and the literal passed in. Am I doing something wrong?:
> >>>
> >>> void bar(int w, ...) {
> >>> ?double d;
> >>> ?va_list ap;
> >>> ?va_start(ap, w);
> >>>
> >>> ?printf("\n\n");
> >>> ?do {
> >>> ? ?d = va_arg(ap, double);
> >>> ? ?printf("d = %f\n", d);
> >>> ?} while (d != 0.0);
> >>> ?va_end(ap);
> >>> }
> >>>
> >>> int main() {
> >>> ?bar(1, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 0.0);
> >>> }
> >>>
> >>
> >> Changing the type of the literal passed in doesn't change the
> >> generated code; they get promoted them to doubles.
> >
> > Yes, but when I use va_arg(ap, float) it does not work (crashes gcc, generates
> > the wrong result with llvm+my patch).
>
> Eli is correct. Any floating point argument that's part of a variable length argument list is always passed as a double. This is part of the C standard. If you're accessing it as a float, you're not going to get correct results on any platform where float and double are of different size.
OK :) So my patch works correctly in all legal cases. May I commit that?
More information about the llvm-commits
mailing list