From be7c870718a46d18186cfebc1fd20ac6b89583f3 Mon Sep 17 00:00:00 2001 From: Vincent Lefevre Date: Thu, 14 Mar 2019 15:39:52 +0100 Subject: [PATCH] Fix va_end() definition: must be an expression of type void Also added a test yielding a failure with the previous definition, i.e. when using: (va_end(ap)); The test also checks potentially incorrect va_start() definition. --- include/stdarg.h | 10 +++++----- tests/tcctest.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/stdarg.h b/include/stdarg.h index 10ce733b..18175c5a 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -25,7 +25,7 @@ void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); #define va_arg(ap, type) \ (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type)))) #define va_copy(dest, src) (*(dest) = *(src)) -#define va_end(ap) +#define va_end(ap) ((void)0) /* avoid conflicting definition for va_list on Macs. */ #define _VA_LIST_T @@ -36,7 +36,7 @@ typedef char *va_list; #define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \ ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8)) #define va_copy(dest, src) ((dest) = (src)) -#define va_end(ap) +#define va_end(ap) ((void)0) #endif #elif __arm__ @@ -48,7 +48,7 @@ typedef char *va_list; #define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \ &~3), *(type *)(ap - ((sizeof(type)+3)&~3))) #define va_copy(dest, src) (dest) = (src) -#define va_end(ap) +#define va_end(ap) ((void)0) #elif defined(__aarch64__) typedef struct { @@ -60,7 +60,7 @@ typedef struct { } va_list; #define va_start(ap, last) __va_start(ap, last) #define va_arg(ap, type) __va_arg(ap, type) -#define va_end(ap) +#define va_end(ap) ((void)0) #define va_copy(dest, src) ((dest) = (src)) #else /* __i386__ */ @@ -69,7 +69,7 @@ typedef char *va_list; #define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3) #define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3))) #define va_copy(dest, src) (dest) = (src) -#define va_end(ap) +#define va_end(ap) ((void)0) #endif /* fix a buggy dependency on GCC in libio.h */ diff --git a/tests/tcctest.c b/tests/tcctest.c index 940e7d07..1d1cc605 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2622,6 +2622,19 @@ void stdarg_for_libc(const char *fmt, ...) va_end(args); } +void stdarg_syntax(int n, ...) +{ + int i; + va_list ap; + if (1) + va_start(ap, n); + else + ; + i = va_arg(ap, int); + printf("stdarg_void_expr: %d\n", i); + (va_end(ap)); +} + void stdarg_test(void) { LONG_DOUBLE ld = 1234567891234LL; @@ -2669,6 +2682,7 @@ void stdarg_test(void) bob.profile = 42; stdarg_for_struct(bob, bob, bob, bob.profile); stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456); + stdarg_syntax(1, 17); } void whitespace_test(void)