1 /* This is just like the default gvarargs.h
2 except for differences described below. */
4 /* Define __gnuc_va_list. */
8 #if ! defined (__svr4__) && ! defined (__linux__) && ! defined (__arch64__)
9 /* This has to be a char * to be compatible with Sun.
10 i.e., we have to pass a `va_list' to vsprintf. */
11 typedef char * __gnuc_va_list;
13 /* This has to be a void * to be compatible with Sun svr4.
14 i.e., we have to pass a `va_list' to vsprintf. */
15 typedef void * __gnuc_va_list;
17 #endif /* not __GNUC_VA_LIST */
19 /* If this is for internal libc use, don't define anything but
21 #if defined (_STDARG_H) || defined (_VARARGS_H)
25 /* Call __builtin_next_arg even though we aren't using its value, so that
26 we can verify that LASTARG is correct. */
27 #if defined (__GCC_NEW_VARARGS__) || defined (__arch64__)
28 #define va_start(AP, LASTARG) \
29 (__builtin_next_arg (LASTARG), AP = (char *) __builtin_saveregs ())
31 #define va_start(AP, LASTARG) \
32 (__builtin_saveregs (), AP = ((char *) __builtin_next_arg (LASTARG)))
37 #define va_alist __builtin_va_alist
38 #define va_dcl int __builtin_va_alist;...
40 #if defined (__GCC_NEW_VARARGS__) || defined (__arch64__)
41 #define va_start(AP) ((AP) = (char *) __builtin_saveregs ())
43 #define va_start(AP) \
44 (__builtin_saveregs (), (AP) = ((char *) &__builtin_va_alist))
50 void va_end (__gnuc_va_list); /* Defined in libgcc.a */
52 /* Values returned by __builtin_classify_type. */
54 enum __va_type_classes {
59 __enumeral_type_class,
62 __reference_type_class,
66 __function_type_class,
78 #define va_end(pvar) ((void)0)
80 /* Avoid errors if compiling GCC v2 with GCC v1. */
85 /* RECORD_TYPE args passed using the C calling convention are
86 passed by invisible reference. ??? RECORD_TYPE args passed
87 in the stack are made to be word-aligned; for an aggregate that is
88 not word-aligned, we advance the pointer to the first non-reg slot. */
92 typedef unsigned int __ptrint __attribute__ ((__mode__ (__DI__)));
94 /* ??? TODO: little endian support */
96 #define va_arg(pvar, TYPE) \
98 (*({int __type = __builtin_classify_type (* (TYPE *) 0); \
100 if (__type == __real_type_class) /* float? */ \
102 if (__alignof__ (TYPE) == 16) \
103 (pvar) = (void *) (((__ptrint) (pvar) + 15) & -16); \
105 (pvar) = (char *) (pvar) + sizeof (TYPE); \
107 else if (__type < __record_type_class) /* integer? */ \
109 (pvar) = (char *) (pvar) + 8; \
110 __result = (char *) (pvar) - sizeof (TYPE); \
112 else /* aggregate object */ \
114 if (sizeof (TYPE) <= 8) \
117 (pvar) = (char *) (pvar) + 8; \
119 else if (sizeof (TYPE) <= 16) \
121 if (__alignof__ (TYPE) == 16) \
122 (pvar) = (void *) (((__ptrint) (pvar) + 15) & -16); \
124 (pvar) = (char *) (pvar) + 16; \
128 __result = * (void **) (pvar); \
129 (pvar) = (char *) (pvar) + 8; \
132 (TYPE *) __result;}))
134 #else /* not __arch64__ */
136 #define __va_rounded_size(TYPE) \
137 (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
139 /* We don't declare the union member `d' to have type TYPE
140 because that would lose in C++ if TYPE has a constructor. */
141 /* We cast to void * and then to TYPE * because this avoids
142 a warning about increasing the alignment requirement.
143 The casts to char * avoid warnings about invalid pointer arithmetic. */
144 #define va_arg(pvar,TYPE) \
146 (*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \
147 || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \
148 && sizeof (TYPE) == 16)) \
149 ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *), \
150 *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \
151 : __va_rounded_size (TYPE) == 8 \
152 ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u; \
153 __u.__i[0] = ((int *) (void *) (pvar))[0]; \
154 __u.__i[1] = ((int *) (void *) (pvar))[1]; \
155 (pvar) = (char *)(pvar) + 8; \
156 (TYPE *) (void *) __u.__d; }) \
157 : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE), \
158 ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));}))
160 #endif /* not __arch64__ */
162 /* Copy __gnuc_va_list into another variable of this type. */
163 #define __va_copy(dest, src) (dest) = (src)
165 #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */