2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic -std=c99
|
2006-10-17 11:00:45 +08:00
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
int __attribute__(()) x;
|
2008-10-20 10:05:46 +08:00
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
__inline void __attribute__((__always_inline__, __nodebug__))
|
2008-10-20 10:05:46 +08:00
|
|
|
foo(void) {
|
2006-10-17 11:00:45 +08:00
|
|
|
}
|
2008-10-20 10:05:46 +08:00
|
|
|
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
__attribute__(()) y; // expected-warning {{defaults to 'int'}}
|
2008-10-20 10:05:46 +08:00
|
|
|
|
|
|
|
// PR2796
|
2009-04-28 11:13:54 +08:00
|
|
|
int (__attribute__(()) *z)(long y);
|
2008-10-20 10:05:46 +08:00
|
|
|
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
void f1(__attribute__(()) int x);
|
2008-10-20 10:05:46 +08:00
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
int f2(y, __attribute__(()) x); // expected-error {{expected identifier}}
|
2008-10-20 10:05:46 +08:00
|
|
|
|
|
|
|
// This is parsed as a normal argument list (with two args that are implicit
|
2009-04-28 11:13:54 +08:00
|
|
|
// int) because the __attribute__ is a declspec.
|
|
|
|
void f3(__attribute__(()) x, // expected-warning {{defaults to 'int'}}
|
2008-10-20 10:05:46 +08:00
|
|
|
y); // expected-warning {{defaults to 'int'}}
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
void f4(__attribute__(())); // expected-error {{expected parameter declarator}}
|
2008-10-20 10:05:46 +08:00
|
|
|
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
// This is ok, the __attribute__ applies to the pointer.
|
|
|
|
int baz(int (__attribute__(()) *x)(long y));
|
2008-10-20 10:05:46 +08:00
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
void g1(void (*f1)(__attribute__(()) int x));
|
|
|
|
void g2(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}}
|
|
|
|
void g3(void (*f3)(__attribute__(()) x, int y)); // expected-warning {{defaults to 'int'}}
|
|
|
|
void g4(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}}
|
2008-10-20 10:05:46 +08:00
|
|
|
|
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
void (*h1)(void (*f1)(__attribute__(()) int x));
|
|
|
|
void (*h2)(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}}
|
2008-10-20 10:05:46 +08:00
|
|
|
|
2009-04-28 11:13:54 +08:00
|
|
|
void (*h3)(void (*f3)(__attribute__(()) x)); // expected-warning {{defaults to 'int'}}
|
|
|
|
void (*h4)(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}}
|
2008-10-20 12:57:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// rdar://6131260
|
|
|
|
int foo42(void) {
|
2009-04-28 11:13:54 +08:00
|
|
|
int x, __attribute__((unused)) y, z;
|
2008-10-20 12:57:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rdar://6096491
|
2009-04-28 11:13:54 +08:00
|
|
|
void __attribute__((noreturn)) d0(void), __attribute__((noreturn)) d1(void);
|
2008-10-20 12:57:38 +08:00
|
|
|
|
2009-11-26 06:58:06 +08:00
|
|
|
void d2(void) __attribute__((noreturn)), d3(void) __attribute__((noreturn));
|
2010-04-12 10:18:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
// PR6287
|
|
|
|
void __attribute__((returns_twice)) returns_twice_test();
|
2011-10-18 05:20:17 +08:00
|
|
|
|
|
|
|
int aligned(int);
|
2013-10-31 09:56:18 +08:00
|
|
|
int __attribute__((vec_type_hint(char, aligned(16) )) missing_rparen_1; // expected-error 2{{expected ')'}} expected-note {{to match}} expected-warning {{does not declare anything}}
|
2011-10-18 05:20:17 +08:00
|
|
|
int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error {{expected ')'}}
|
|
|
|
int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error {{expected ')'}}
|
2012-02-17 00:50:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int testFundef1(int *a) __attribute__((nonnull(1))) { // \
|
2014-01-03 02:10:17 +08:00
|
|
|
// expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
|
2012-02-17 00:50:43 +08:00
|
|
|
return *a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// noreturn is lifted to type qualifier
|
|
|
|
void testFundef2() __attribute__((noreturn)) { // \
|
2014-01-03 02:10:17 +08:00
|
|
|
// expected-warning {{GCC does not allow 'noreturn' attribute in this position on a function definition}}
|
2012-02-17 00:50:43 +08:00
|
|
|
testFundef2();
|
|
|
|
}
|
|
|
|
|
|
|
|
int testFundef3(int *a) __attribute__((nonnull(1), // \
|
2014-01-03 02:10:17 +08:00
|
|
|
// expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
|
2012-02-17 00:50:43 +08:00
|
|
|
pure)) { // \
|
2014-01-03 02:10:17 +08:00
|
|
|
// expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
|
2012-02-17 00:50:43 +08:00
|
|
|
return *a;
|
|
|
|
}
|
|
|
|
|
|
|
|
int testFundef4(int *a) __attribute__((nonnull(1))) // \
|
2014-01-03 02:10:17 +08:00
|
|
|
// expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
|
2012-02-17 00:50:43 +08:00
|
|
|
__attribute((pure)) { // \
|
2014-01-03 02:10:17 +08:00
|
|
|
// expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
|
2012-02-17 00:50:43 +08:00
|
|
|
return *a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GCC allows these
|
|
|
|
void testFundef5() __attribute__(()) { }
|
|
|
|
|
|
|
|
__attribute__((pure)) int testFundef6(int a) { return a; }
|
|
|
|
|
|
|
|
|
|
|
|
|