From 222e2a7620e6520ffaf4fc4e69d79c18da31542e Mon Sep 17 00:00:00 2001 From: "Zancanaro; Carlo" Date: Mon, 24 Sep 2012 09:58:17 +1000 Subject: Add the clang library to the repo (with some of my changes, too). --- clang/test/Sema/varargs.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 clang/test/Sema/varargs.c (limited to 'clang/test/Sema/varargs.c') diff --git a/clang/test/Sema/varargs.c b/clang/test/Sema/varargs.c new file mode 100644 index 0000000..07081ed --- /dev/null +++ b/clang/test/Sema/varargs.c @@ -0,0 +1,78 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9 + +void f1(int a) +{ + __builtin_va_list ap; + + __builtin_va_start(ap, a, a); // expected-error {{too many arguments to function}} + __builtin_va_start(ap, a); // expected-error {{'va_start' used in function with fixed args}} +} + +void f2(int a, int b, ...) +{ + __builtin_va_list ap; + + __builtin_va_start(ap, 10); // expected-warning {{second parameter of 'va_start' not last named argument}} + __builtin_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}} + __builtin_va_start(ap, b); +} + +void f3(float a, ...) +{ + __builtin_va_list ap; + + __builtin_va_start(ap, a); + __builtin_va_start(ap, (a)); +} + + +// stdarg: PR3075 +void f4(const char *msg, ...) { + __builtin_va_list ap; + __builtin_stdarg_start((ap), (msg)); + __builtin_va_end (ap); +} + +void f5() { + __builtin_va_list ap; + __builtin_va_start(ap,ap); // expected-error {{'va_start' used in function with fixed args}} +} + +void f6(int a, ...) { + __builtin_va_list ap; + __builtin_va_start(ap); // expected-error {{too few arguments to function}} +} + +// PR3350 +void +foo(__builtin_va_list authors, ...) { + __builtin_va_start (authors, authors); + (void)__builtin_va_arg(authors, int); + __builtin_va_end (authors); +} + +void f7(int a, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, a); + // FIXME: This error message is sub-par. + __builtin_va_arg(ap, int) = 1; // expected-error {{expression is not assignable}} + int *x = &__builtin_va_arg(ap, int); // expected-error {{address expression must be an lvalue or a function designator}} + __builtin_va_end(ap); +} + +void f8(int a, ...) { + __builtin_va_list ap; + __builtin_va_start(ap, a); + (void)__builtin_va_arg(ap, void); // expected-error {{second argument to 'va_arg' is of incomplete type 'void'}} + __builtin_va_end(ap); +} + +enum E { x = -1, y = 2, z = 10000 }; +void f9(__builtin_va_list args) +{ + (void)__builtin_va_arg(args, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'}} + (void)__builtin_va_arg(args, enum E); // Don't warn here in C + (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}} + (void)__builtin_va_arg(args, char); // expected-warning {{second argument to 'va_arg' is of promotable type 'char'}} +} -- cgit v1.2.3