History

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.

Vincent Lefevre committed 7 years ago

Commit be7c8701 parent 920f7732 files · +19 −5Browse files

Unified · Split

2 files
  1. include/stdarg.h +5 −5
  2. tests/tcctest.c +14 −0
include/stdarg.h+5−5
@@ -25,7 +25,7 @@ void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align); · 24 unmodified lines
25#define va_arg(ap, type) \25#define va_arg(ap, type) \
26 (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))26 (*(type *)(__va_arg(ap, __builtin_va_arg_types(type), sizeof(type), __alignof__(type))))
27#define va_copy(dest, src) (*(dest) = *(src))27#define va_copy(dest, src) (*(dest) = *(src))
28#define va_end(ap)28#define va_end(ap) ((void)0)
29 29
30/* avoid conflicting definition for va_list on Macs. */30/* avoid conflicting definition for va_list on Macs. */
31#define _VA_LIST_T31#define _VA_LIST_T
@@ -36,7 +36,7 @@ typedef char *va_list; · 4 unmodified lines
36#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \36#define va_arg(ap, t) ((sizeof(t) > 8 || (sizeof(t) & (sizeof(t) - 1))) \
37 ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))37 ? **(t **)((ap += 8) - 8) : *(t *)((ap += 8) - 8))
38#define va_copy(dest, src) ((dest) = (src))38#define va_copy(dest, src) ((dest) = (src))
39#define va_end(ap)39#define va_end(ap) ((void)0)
40#endif40#endif
41 41
42#elif __arm__42#elif __arm__
@@ -48,7 +48,7 @@ typedef char *va_list; · 5 unmodified lines
48#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \48#define va_arg(ap,type) (ap = (void *) ((_tcc_align(ap,type)+sizeof(type)+3) \
49 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))49 &~3), *(type *)(ap - ((sizeof(type)+3)&~3)))
50#define va_copy(dest, src) (dest) = (src)50#define va_copy(dest, src) (dest) = (src)
51#define va_end(ap)51#define va_end(ap) ((void)0)
52 52
53#elif defined(__aarch64__)53#elif defined(__aarch64__)
54typedef struct {54typedef struct {
@@ -60,7 +60,7 @@ typedef struct { · 5 unmodified lines
60} va_list;60} va_list;
61#define va_start(ap, last) __va_start(ap, last)61#define va_start(ap, last) __va_start(ap, last)
62#define va_arg(ap, type) __va_arg(ap, type)62#define va_arg(ap, type) __va_arg(ap, type)
63#define va_end(ap)63#define va_end(ap) ((void)0)
64#define va_copy(dest, src) ((dest) = (src))64#define va_copy(dest, src) ((dest) = (src))
65 65
66#else /* __i386__ */66#else /* __i386__ */
@@ -69,7 +69,7 @@ typedef char *va_list; · 2 unmodified lines
69#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)69#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
70#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))70#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
71#define va_copy(dest, src) (dest) = (src)71#define va_copy(dest, src) (dest) = (src)
72#define va_end(ap)72#define va_end(ap) ((void)0)
73#endif73#endif
74 74
75/* fix a buggy dependency on GCC in libio.h */75/* fix a buggy dependency on GCC in libio.h */
tests/tcctest.c+14−0
@@ -2622,6 +2622,19 @@ void stdarg_for_libc(const char *fmt, ...) · 2621 unmodified lines
2622 va_end(args);2622 va_end(args);
2623}2623}
2624 2624
2625void stdarg_syntax(int n, ...)
2626{
2627 int i;
2628 va_list ap;
2629 if (1)
2630 va_start(ap, n);
2631 else
2632 ;
2633 i = va_arg(ap, int);
2634 printf("stdarg_void_expr: %d\n", i);
2635 (va_end(ap));
2636}
2637
2625void stdarg_test(void)2638void stdarg_test(void)
2626{2639{
2627 LONG_DOUBLE ld = 1234567891234LL;2640 LONG_DOUBLE ld = 1234567891234LL;
@@ -2669,6 +2682,7 @@ void stdarg_test(void) · 41 unmodified lines
2669 bob.profile = 42;2682 bob.profile = 42;
2670 stdarg_for_struct(bob, bob, bob, bob.profile);2683 stdarg_for_struct(bob, bob, bob, bob.profile);
2671 stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456);2684 stdarg_for_libc("stdarg_for_libc: %s %.2f %d\n", "string", 1.23, 456);
2685 stdarg_syntax(1, 17);
2672}2686}
2673 2687
2674void whitespace_test(void)2688void whitespace_test(void)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t