use compiler builtins for variadic macros when available
authorRich Felker <dalias@aerifal.cx>
Thu, 28 Apr 2011 03:41:48 +0000 (23:41 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 28 Apr 2011 03:41:48 +0000 (23:41 -0400)
this slightly cuts down on the degree musl "fights with" gcc, but more
importantly, it fixes a critical bug when gcc inlines a variadic
function and optimizes out the variadic arguments due to noticing that
they were "not used" (by __builtin_va_arg).

we leave the old code in place if __GNUC__ >= 3 is false; it seems
like it might be necessary at least for tinycc support and perhaps if
anyone ever gets around to fixing gcc 2.95.3 enough to make it work..

arch/i386/bits/alltypes.h.sh
arch/x86_64/bits/stdarg.h
include/stdarg.h

index 9d94c91..335c095 100755 (executable)
@@ -19,7 +19,12 @@ union \1 \2;\
 TYPEDEF unsigned size_t;
 TYPEDEF int ssize_t;
 TYPEDEF long ptrdiff_t;
 TYPEDEF unsigned size_t;
 TYPEDEF int ssize_t;
 TYPEDEF long ptrdiff_t;
+
+#if __GNUC__ >= 3
+TYPEDEF __builtin_va_list va_list;
+#else
 TYPEDEF struct __va_list * va_list;
 TYPEDEF struct __va_list * va_list;
+#endif
 
 TYPEDEF long wchar_t;
 TYPEDEF long wint_t;
 
 TYPEDEF long wchar_t;
 TYPEDEF long wint_t;
index 24b679c..fde3781 100644 (file)
@@ -2,4 +2,3 @@
 #define va_end(v)       __builtin_va_end(v)
 #define va_arg(v,l)     __builtin_va_arg(v,l)
 #define va_copy(d,s)    __builtin_va_copy(d,s)
 #define va_end(v)       __builtin_va_end(v)
 #define va_arg(v,l)     __builtin_va_arg(v,l)
 #define va_copy(d,s)    __builtin_va_copy(d,s)
-#define __va_copy(d,s)  __builtin_va_copy(d,s)
index 2e18e5f..60d4e2a 100644 (file)
@@ -9,7 +9,14 @@ extern "C" {
 
 #include <bits/alltypes.h>
 
 
 #include <bits/alltypes.h>
 
+#if __GNUC__ >= 3
+#define va_start(v,l)   __builtin_va_start(v,l)
+#define va_end(v)       __builtin_va_end(v)
+#define va_arg(v,l)     __builtin_va_arg(v,l)
+#define va_copy(d,s)    __builtin_va_copy(d,s)
+#else
 #include <bits/stdarg.h>
 #include <bits/stdarg.h>
+#endif
 
 #ifdef __cplusplus
 }
 
 #ifdef __cplusplus
 }