Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s && |
| 2 | // RUN: clang-cc -fsyntax-only -verify %s -triple x86_64-apple-darwin9 |
Anders Carlsson | 6eda8c9 | 2007-10-12 17:48:41 +0000 | [diff] [blame] | 3 | |
| 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 | |
| 12 | void f2(int a, int b, ...) |
| 13 | { |
| 14 | __builtin_va_list ap; |
| 15 | |
| 16 | __builtin_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}} |
| 17 | __builtin_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}} |
| 18 | __builtin_va_start(ap, b); |
| 19 | } |
Anders Carlsson | 88cf226 | 2008-02-11 04:20:54 +0000 | [diff] [blame] | 20 | |
| 21 | void f3(float a, ...) |
| 22 | { |
| 23 | __builtin_va_list ap; |
| 24 | |
| 25 | __builtin_va_start(ap, a); |
| 26 | __builtin_va_start(ap, (a)); |
| 27 | } |
Chris Lattner | 58ace88 | 2008-11-16 18:43:46 +0000 | [diff] [blame] | 28 | |
| 29 | |
| 30 | // stdarg: PR3075 |
| 31 | void f4(const char *msg, ...) { |
| 32 | __builtin_va_list ap; |
| 33 | __builtin_stdarg_start((ap), (msg)); |
| 34 | __builtin_va_end (ap); |
| 35 | } |
| 36 | |
Eli Friedman | 56f20ae | 2008-12-15 22:05:35 +0000 | [diff] [blame] | 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 | |
| 42 | void f6(int a, ...) { |
| 43 | __builtin_va_list ap; |
| 44 | __builtin_va_start(ap); // expected-error {{too few arguments to function}} |
| 45 | } |
Eli Friedman | 6597f98 | 2009-01-20 07:46:22 +0000 | [diff] [blame] | 46 | |
| 47 | // PR3350 |
| 48 | void |
| 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 | |
Daniel Dunbar | adadd8d | 2009-02-12 09:21:08 +0000 | [diff] [blame] | 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 {{non-object type 'int' is not assignable}} |
| 60 | int *x = &__builtin_va_arg(ap, int); // expected-error {{address expression must be an lvalue or a function designator}} |
| 61 | __builtin_va_end(ap); |
| 62 | } |
Chris Lattner | f502691 | 2009-04-05 00:52:59 +0000 | [diff] [blame] | 63 | |