• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
2 
3 // rdar://6726818
f1()4 void f1() {
5   const __builtin_va_list args2;
6   (void)__builtin_va_arg(args2, int); // expected-error {{first argument to 'va_arg' is of type 'const __builtin_va_list' and not 'va_list'}}
7 }
8 
f2(int a,...)9 void f2(int a, ...) {
10   __builtin_ms_va_list ap;
11   __builtin_ms_va_start(ap, a); // expected-error {{'__builtin_ms_va_start' used in System V ABI function}}
12 }
13 
g1(int a)14 void __attribute__((ms_abi)) g1(int a) {
15   __builtin_ms_va_list ap;
16 
17   __builtin_ms_va_start(ap, a, a); // expected-error {{too many arguments to function}}
18   __builtin_ms_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}}
19 }
20 
g2(int a,int b,...)21 void __attribute__((ms_abi)) g2(int a, int b, ...) {
22   __builtin_ms_va_list ap;
23 
24   __builtin_ms_va_start(ap, 10); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
25   __builtin_ms_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
26   __builtin_ms_va_start(ap, b);
27 }
28 
g3(float a,...)29 void __attribute__((ms_abi)) g3(float a, ...) { // expected-note 2{{parameter of type 'float' is declared here}}
30   __builtin_ms_va_list ap;
31 
32   __builtin_ms_va_start(ap, a); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
33   __builtin_ms_va_start(ap, (a)); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
34 }
35 
g5()36 void __attribute__((ms_abi)) g5() {
37   __builtin_ms_va_list ap;
38   __builtin_ms_va_start(ap, ap); // expected-error {{'va_start' used in function with fixed args}}
39 }
40 
g6(int a,...)41 void __attribute__((ms_abi)) g6(int a, ...) {
42   __builtin_ms_va_list ap;
43   __builtin_ms_va_start(ap); // expected-error {{too few arguments to function}}
44 }
45 
46 void __attribute__((ms_abi))
bar(__builtin_ms_va_list authors,...)47 bar(__builtin_ms_va_list authors, ...) {
48   __builtin_ms_va_start(authors, authors);
49   (void)__builtin_va_arg(authors, int);
50   __builtin_ms_va_end(authors);
51 }
52 
g7(int a,...)53 void __attribute__((ms_abi)) g7(int a, ...) {
54   __builtin_ms_va_list ap;
55   __builtin_ms_va_start(ap, a);
56   // FIXME: This error message is sub-par.
57   __builtin_va_arg(ap, int) = 1; // expected-error {{expression is not assignable}}
58   int *x = &__builtin_va_arg(ap, int); // expected-error {{cannot take the address of an rvalue}}
59   __builtin_ms_va_end(ap);
60 }
61 
g8(int a,...)62 void __attribute__((ms_abi)) g8(int a, ...) {
63   __builtin_ms_va_list ap;
64   __builtin_ms_va_start(ap, a);
65   (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}}
66   __builtin_ms_va_end(ap);
67 }
68 
69 enum E { x = -1, y = 2, z = 10000 };
g9(__builtin_ms_va_list args)70 void __attribute__((ms_abi)) g9(__builtin_ms_va_list args) {
71   (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}}
72   (void)__builtin_va_arg(args, enum E); // no-warning
73   (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}}
74   (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}}
75 }
76 
g10(int a,...)77 void __attribute__((ms_abi)) g10(int a, ...) {
78   __builtin_va_list ap;
79   __builtin_va_start(ap, a); // expected-error {{'va_start' used in Win64 ABI function}}
80 }
81