1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
3
f1(int a)4 void f1(int a)
5 {
6 __builtin_va_list ap;
7
8 __builtin_va_start(ap, a, a); // expected-error {{too many arguments to function}}
9 __builtin_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
10 }
11
f2(int a,int b,...)12 void f2(int a, int b, ...)
13 {
14 __builtin_va_list ap;
15
16 __builtin_va_start(ap, 10); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
17 __builtin_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
18 __builtin_va_start(ap, b);
19 }
20
f3(float a,...)21 void f3(float a, ...) { // expected-note 2{{parameter of type 'float' is declared here}}
22 __builtin_va_list ap;
23
24 __builtin_va_start(ap, a); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
25 __builtin_va_start(ap, (a)); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
26 }
27
28
29 // stdarg: PR3075
f4(const char * msg,...)30 void f4(const char *msg, ...) {
31 __builtin_va_list ap;
32 __builtin_stdarg_start((ap), (msg));
33 __builtin_va_end (ap);
34 }
35
f5()36 void f5() {
37 __builtin_va_list ap;
38 __builtin_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}}
39 }
40
f6(int a,...)41 void f6(int a, ...) {
42 __builtin_va_list ap;
43 __builtin_va_start(ap); // expected-error {{too few arguments to function}}
44 }
45
46 // PR3350
47 void
foo(__builtin_va_list authors,...)48 foo(__builtin_va_list authors, ...) {
49 __builtin_va_start (authors, authors);
50 (void)__builtin_va_arg(authors, int);
51 __builtin_va_end (authors);
52 }
53
f7(int a,...)54 void f7(int a, ...) {
55 __builtin_va_list ap;
56 __builtin_va_start(ap, a);
57 // FIXME: This error message is sub-par.
58 __builtin_va_arg(ap, int) = 1; // expected-error {{expression is not assignable}}
59 int *x = &__builtin_va_arg(ap, int); // expected-error {{cannot take the address of an rvalue}}
60 __builtin_va_end(ap);
61 }
62
f8(int a,...)63 void f8(int a, ...) {
64 __builtin_va_list ap;
65 __builtin_va_start(ap, a);
66 (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}}
67 __builtin_va_end(ap);
68 }
69
70 enum E { x = -1, y = 2, z = 10000 };
f9(__builtin_va_list args)71 void f9(__builtin_va_list args)
72 {
73 (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}}
74 (void)__builtin_va_arg(args, enum E); // Don't warn here in C
75 (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}}
76 (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}}
77 }
78
f10(int a,...)79 void f10(int a, ...) {
80 int i;
81 __builtin_va_list ap;
82 i = __builtin_va_start(ap, a); // expected-error {{assigning to 'int' from incompatible type 'void'}}
83 __builtin_va_end(ap);
84 }
85
f11(short s,...)86 void f11(short s, ...) { // expected-note {{parameter of type 'short' is declared here}}
87 __builtin_va_list ap;
88 __builtin_va_start(ap, s); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
89 __builtin_va_end(ap);
90 }
91
f12(register int i,...)92 void f12(register int i, ...) { // expected-note {{parameter of type 'int' is declared here}}
93 __builtin_va_list ap;
94 __builtin_va_start(ap, i); // expected-warning {{passing a parameter declared with the 'register' keyword to 'va_start' has undefined behavior}}
95 __builtin_va_end(ap);
96 }
97