1 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
3 // RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s -triple x86_64-pc-win32
4 
f1(int a)5 void f1(int a)
6 {
7     __builtin_va_list ap;
8 
9     __builtin_va_start(ap, a, a); // expected-error {{too many arguments to function}}
10     __builtin_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
11 }
12 
f2(int a,int b,...)13 void f2(int a, int b, ...)
14 {
15     __builtin_va_list ap;
16 
17     __builtin_va_start(ap, 10); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
18     __builtin_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
19     __builtin_va_start(ap, b);
20 }
21 
f3(float a,...)22 void f3(float a, ...) { // expected-note 2{{parameter of type 'float' is declared here}}
23     __builtin_va_list ap;
24 
25     __builtin_va_start(ap, a); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
26     __builtin_va_start(ap, (a)); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
27 }
28 
29 
30 // stdarg: PR3075 and PR2531
f4(const char * msg,...)31 void f4(const char *msg, ...) {
32  __builtin_va_list ap;
33  __builtin_stdarg_start((ap), (msg));
34  __builtin_va_end (ap);
35 }
36 
f5()37 void f5() {
38   __builtin_va_list ap;
39   __builtin_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}}
40 }
41 
f6(int a,...)42 void f6(int a, ...) {
43   __builtin_va_list ap;
44   __builtin_va_start(ap); // expected-error {{too few arguments to function}}
45 }
46 
47 // PR3350
48 void
foo(__builtin_va_list authors,...)49 foo(__builtin_va_list authors, ...) {
50   __builtin_va_start (authors, authors);
51   (void)__builtin_va_arg(authors, int);
52   __builtin_va_end (authors);
53 }
54 
f7(int a,...)55 void f7(int a, ...) {
56   __builtin_va_list ap;
57   __builtin_va_start(ap, a);
58   // FIXME: This error message is sub-par.
59   __builtin_va_arg(ap, int) = 1; // expected-error {{expression is not assignable}}
60   int *x = &__builtin_va_arg(ap, int); // expected-error {{cannot take the address of an rvalue}}
61   __builtin_va_end(ap);
62 }
63 
f8(int a,...)64 void f8(int a, ...) {
65   __builtin_va_list ap;
66   __builtin_va_start(ap, a);
67   (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}}
68   __builtin_va_end(ap);
69 }
70 
71 enum E { x = -1, y = 2, z = 10000 };
f9(__builtin_va_list args)72 void f9(__builtin_va_list args)
73 {
74     (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}}
75     (void)__builtin_va_arg(args, enum E); // Don't warn here in C
76     (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}}
77     (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}}
78 }
79 
f10(int a,...)80 void f10(int a, ...) {
81   int i;
82   __builtin_va_list ap;
83   i = __builtin_va_start(ap, a); // expected-error {{assigning to 'int' from incompatible type 'void'}}
84   __builtin_va_end(ap);
85 }
86 
f11(short s,...)87 void f11(short s, ...) {  // expected-note {{parameter of type 'short' is declared here}}
88   __builtin_va_list ap;
89   __builtin_va_start(ap, s); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
90   __builtin_va_end(ap);
91 }
92 
f12(register int i,...)93 void f12(register int i, ...) {  // expected-note {{parameter of type 'int' is declared here}}
94   __builtin_va_list ap;
95   __builtin_va_start(ap, i); // expected-warning {{passing a parameter declared with the 'register' keyword to 'va_start' has undefined behavior}}
96   __builtin_va_end(ap);
97 }
98 
99 enum __attribute__((packed)) E1 {
100   one1
101 };
102 
f13(enum E1 e,...)103 void f13(enum E1 e, ...) {
104   __builtin_va_list va;
105   __builtin_va_start(va, e);
106 #ifndef MS
107   // In Microsoft compatibility mode, all enum types are int, but in
108   // non-ms-compatibility mode, this enumeration type will undergo default
109   // argument promotions.
110   // expected-note@-7 {{parameter of type 'enum E1' is declared here}}
111   // expected-warning@-6 {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
112 #endif
113   __builtin_va_end(va);
114 }
115 
f14(int e,...)116 void f14(int e, ...) {
117   // expected-warning@+3 {{implicitly declaring library function 'va_start'}}
118   // expected-note@+2 {{include the header <stdarg.h>}}
119   // expected-error@+1 {{too few arguments to function call}}
120   va_start();
121   __builtin_va_list va;
122   va_start(va, e);
123 }
124