Add missing const and add warning flags
[tinycc.git] / include / stdarg.h
blob9adfc610a0bd99cc9205388beb3c68895b0053f8
1 #ifndef _STDARG_H
2 #define _STDARG_H
4 #ifdef __x86_64__
5 #ifndef _WIN64
7 //This should be in sync with the declaration on our lib/libtcc1.c
8 /* GCC compatible definition of va_list. */
9 typedef struct {
10 unsigned int gp_offset;
11 unsigned int fp_offset;
12 union {
13 unsigned int overflow_offset;
14 char *overflow_arg_area;
16 char *reg_save_area;
17 } __va_list_struct;
19 /* Avoid conflicting definition for va_list on musl libc */
20 #ifndef __DEFINED_va_list
21 typedef __va_list_struct va_list[1];
22 #define __DEFINED_va_list
23 #endif
25 void __va_start(__va_list_struct *ap, void *fp);
26 void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
28 #define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
29 #define va_arg(ap, type) \
30 (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
31 #define va_copy(dest, src) (*(dest) = *(src))
32 #define va_end(ap)
34 /* avoid conflicting definition for va_list on Macs. */
35 #define _VA_LIST_T
37 #else /* _WIN64 */
38 typedef char *va_list;
39 #define va_start(ap,last) __builtin_va_start(ap,last)
40 #define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
41 ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
42 #define va_copy(dest, src) ((dest) = (src))
43 #define va_end(ap)
44 #endif
46 #elif __arm__
47 typedef char *va_list;
48 #define _tcc_alignof(type) ((int)&((struct {char c;type x;} *)0)->x)
49 #define _tcc_align(addr,type) (((unsigned)addr + _tcc_alignof(type) - 1) \
50 & ~(_tcc_alignof(type) - 1))
51 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
52 #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
53 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
54 #define va_copy(dest, src) (dest) = (src)
55 #define va_end(ap)
57 #elif defined(__aarch64__)
58 typedef struct {
59 void *__stack;
60 void *__gr_top;
61 void *__vr_top;
62 int __gr_offs;
63 int __vr_offs;
64 } va_list;
65 #define va_start(ap, last) __va_start(ap, last)
66 #define va_arg(ap, type) __va_arg(ap, type)
67 #define va_end(ap)
68 #define va_copy(dest, src) ((dest) = (src))
70 #else /* __i386__ */
71 typedef char *va_list;
72 /* only correct for i386 */
73 #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
74 #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
75 #define va_copy(dest, src) (dest) = (src)
76 #define va_end(ap)
77 #endif
79 /* fix a buggy dependency on GCC in libio.h */
80 typedef va_list __gnuc_va_list;
81 #define _VA_LIST_DEFINED
83 #endif /* _STDARG_H */