2016-09-16 02:07:51 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
|
2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
|
2016-09-16 02:07:51 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s -triple x86_64-pc-win32
|
2007-10-13 01:48:41 +08:00
|
|
|
|
|
|
|
void f1(int a)
|
|
|
|
{
|
|
|
|
__builtin_va_list ap;
|
2016-04-19 02:10:53 +08:00
|
|
|
|
2007-10-13 01:48:41 +08:00
|
|
|
__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;
|
2016-04-19 02:10:53 +08:00
|
|
|
|
|
|
|
__builtin_va_start(ap, 10); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
|
|
|
|
__builtin_va_start(ap, a); // expected-warning {{second argument to 'va_start' is not the last named parameter}}
|
2007-10-13 01:48:41 +08:00
|
|
|
__builtin_va_start(ap, b);
|
|
|
|
}
|
2008-02-11 12:20:54 +08:00
|
|
|
|
2016-04-24 21:30:21 +08:00
|
|
|
void f3(float a, ...) { // expected-note 2{{parameter of type 'float' is declared here}}
|
2008-02-11 12:20:54 +08:00
|
|
|
__builtin_va_list ap;
|
2016-04-19 02:10:53 +08:00
|
|
|
|
2016-04-24 21:30:21 +08:00
|
|
|
__builtin_va_start(ap, a); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
|
|
|
|
__builtin_va_start(ap, (a)); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
|
2008-02-11 12:20:54 +08:00
|
|
|
}
|
2008-11-17 02:43:46 +08:00
|
|
|
|
|
|
|
|
2017-05-03 04:10:03 +08:00
|
|
|
// stdarg: PR3075 and PR2531
|
2008-11-17 02:43:46 +08:00
|
|
|
void f4(const char *msg, ...) {
|
|
|
|
__builtin_va_list ap;
|
|
|
|
__builtin_stdarg_start((ap), (msg));
|
|
|
|
__builtin_va_end (ap);
|
|
|
|
}
|
|
|
|
|
2008-12-16 06:05:35 +08:00
|
|
|
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}}
|
|
|
|
}
|
2009-01-20 15:46:22 +08:00
|
|
|
|
|
|
|
// PR3350
|
|
|
|
void
|
|
|
|
foo(__builtin_va_list authors, ...) {
|
|
|
|
__builtin_va_start (authors, authors);
|
|
|
|
(void)__builtin_va_arg(authors, int);
|
|
|
|
__builtin_va_end (authors);
|
|
|
|
}
|
|
|
|
|
2009-02-12 17:21:08 +08:00
|
|
|
void f7(int a, ...) {
|
|
|
|
__builtin_va_list ap;
|
|
|
|
__builtin_va_start(ap, a);
|
|
|
|
// FIXME: This error message is sub-par.
|
2009-05-04 06:36:05 +08:00
|
|
|
__builtin_va_arg(ap, int) = 1; // expected-error {{expression is not assignable}}
|
2013-02-02 10:14:45 +08:00
|
|
|
int *x = &__builtin_va_arg(ap, int); // expected-error {{cannot take the address of an rvalue}}
|
2009-02-12 17:21:08 +08:00
|
|
|
__builtin_va_end(ap);
|
|
|
|
}
|
2009-04-05 08:52:59 +08:00
|
|
|
|
2011-06-14 13:17:32 +08:00
|
|
|
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);
|
|
|
|
}
|
2011-07-12 05:45:59 +08:00
|
|
|
|
|
|
|
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'}}
|
|
|
|
}
|
2013-11-07 16:14:26 +08:00
|
|
|
|
|
|
|
void f10(int a, ...) {
|
|
|
|
int i;
|
|
|
|
__builtin_va_list ap;
|
|
|
|
i = __builtin_va_start(ap, a); // expected-error {{assigning to 'int' from incompatible type 'void'}}
|
|
|
|
__builtin_va_end(ap);
|
|
|
|
}
|
2016-04-24 21:30:21 +08:00
|
|
|
|
|
|
|
void f11(short s, ...) { // expected-note {{parameter of type 'short' is declared here}}
|
|
|
|
__builtin_va_list ap;
|
|
|
|
__builtin_va_start(ap, s); // expected-warning {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
|
|
|
|
__builtin_va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void f12(register int i, ...) { // expected-note {{parameter of type 'int' is declared here}}
|
|
|
|
__builtin_va_list ap;
|
|
|
|
__builtin_va_start(ap, i); // expected-warning {{passing a parameter declared with the 'register' keyword to 'va_start' has undefined behavior}}
|
|
|
|
__builtin_va_end(ap);
|
|
|
|
}
|
2016-09-16 02:07:51 +08:00
|
|
|
|
|
|
|
enum __attribute__((packed)) E1 {
|
|
|
|
one1
|
|
|
|
};
|
|
|
|
|
|
|
|
void f13(enum E1 e, ...) {
|
|
|
|
__builtin_va_list va;
|
|
|
|
__builtin_va_start(va, e);
|
|
|
|
#ifndef MS
|
|
|
|
// In Microsoft compatibility mode, all enum types are int, but in
|
|
|
|
// non-ms-compatibility mode, this enumeration type will undergo default
|
|
|
|
// argument promotions.
|
|
|
|
// expected-note@-7 {{parameter of type 'enum E1' is declared here}}
|
|
|
|
// expected-warning@-6 {{passing an object that undergoes default argument promotion to 'va_start' has undefined behavior}}
|
|
|
|
#endif
|
|
|
|
__builtin_va_end(va);
|
|
|
|
}
|