tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] x86_64: second struct va_arg fails


From: Henry Kroll
Subject: Re: [Tinycc-devel] x86_64: second struct va_arg fails
Date: Wed, 15 Dec 2010 16:06:46 -0800

On Wed, 2010-12-15 at 03:07 +0100, grischka wrote:
> Henry Kroll wrote:
> > x86_64 fails to copy the second struct passed to va_arg.
> > 
> > static struct myspace {
> >     short int profile;
> > } bob = { 42 };
> > 
> > void badfunc(int eek, ...) {
> >     va_list ack;
> >     int validate;
> >     struct myspace george, bill;
> >     va_start(ack, eek);
> >         bill     = va_arg(ack, struct myspace);
> >         george   = va_arg(ack, struct myspace);
> >         validate = va_arg(ack, int);
> > [...]
> > int main(int argc, char **argv) {
> >     badfunc(0, bob, bob, bob.profile);
> > [...]
> 
> This line from tcc's include/stdarg.h might give a hint:
>      /* XXX: this lacks the support of aggregated types. */                  \
> 
> I have no idea though how such support would look like.
> 
> Btw. on win64 it does not work either.  I must have misunderstood
> something about the structures part of the calling conventions.
> 
> --- grischka
> 
> 
> _______________________________________________
> Tinycc-devel mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/tinycc-devel

This passes some hurried tests I threw at it, but I'm sure it needs more
type checking. I used the attached test program to generate a map of
ap->overflow_arg_area for various sized structures.

diff --git a/include/stdarg.h b/include/stdarg.h
index b5844d0..7b52d3d 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
@@ -39,8 +39,11 @@ typedef struct __va_list_struct *va_list;
                  : (ap->overflow_arg_area += 8,                 \
                     ap->overflow_arg_area - 8))                 \
               : (ap->gp_offset < 48                             \
-                 ? (ap->gp_offset += 8,                         \
-                    ap->reg_save_area + ap->gp_offset - 8)      \
+    ? __builtin_types_compatible_p(type, int)                   \
+        ? (ap->gp_offset += 8,                                  \
+           ap->reg_save_area + ap->gp_offset - 8)               \
+        : (ap->overflow_arg_area += (sizeof(type) + 3 & ~3),    \
+           ap->overflow_arg_area - (sizeof(type) + 3 & ~3))     \
                  : (ap->overflow_arg_area += 8,                 \
                     ap->overflow_arg_area - 8))                 \
         ))

Attachment: test.c
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]