Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic -std=c99 |
Chris Lattner | 43ec2ce | 2006-10-17 03:00:45 +0000 | [diff] [blame] | 2 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 3 | int __attribute__(()) x; |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 4 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 5 | __inline void __attribute__((__always_inline__, __nodebug__)) |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 6 | foo(void) { |
Chris Lattner | 43ec2ce | 2006-10-17 03:00:45 +0000 | [diff] [blame] | 7 | } |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 8 | |
| 9 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 10 | __attribute__(()) y; // expected-warning {{defaults to 'int'}} |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 11 | |
| 12 | // PR2796 |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 13 | int (__attribute__(()) *z)(long y); |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 14 | |
| 15 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 16 | void f1(__attribute__(()) int x); |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 17 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 18 | int f2(y, __attribute__(()) x); // expected-error {{expected identifier}} |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 19 | |
| 20 | // This is parsed as a normal argument list (with two args that are implicit |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 21 | // int) because the __attribute__ is a declspec. |
| 22 | void f3(__attribute__(()) x, // expected-warning {{defaults to 'int'}} |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 23 | y); // expected-warning {{defaults to 'int'}} |
| 24 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 25 | void f4(__attribute__(())); // expected-error {{expected parameter declarator}} |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 26 | |
| 27 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 28 | // This is ok, the __attribute__ applies to the pointer. |
| 29 | int baz(int (__attribute__(()) *x)(long y)); |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 30 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 31 | void g1(void (*f1)(__attribute__(()) int x)); |
| 32 | void g2(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}} |
| 33 | void g3(void (*f3)(__attribute__(()) x, int y)); // expected-warning {{defaults to 'int'}} |
| 34 | void g4(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}} |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 35 | |
| 36 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 37 | void (*h1)(void (*f1)(__attribute__(()) int x)); |
| 38 | void (*h2)(int (*f2)(y, __attribute__(()) x)); // expected-error {{expected identifier}} |
Chris Lattner | 8ff2c6c | 2008-10-20 02:05:46 +0000 | [diff] [blame] | 39 | |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 40 | void (*h3)(void (*f3)(__attribute__(()) x)); // expected-warning {{defaults to 'int'}} |
| 41 | void (*h4)(void (*f4)(__attribute__(()))); // expected-error {{expected parameter declarator}} |
Chris Lattner | 29e6f2b | 2008-10-20 04:57:38 +0000 | [diff] [blame] | 42 | |
| 43 | |
| 44 | |
| 45 | // rdar://6131260 |
| 46 | int foo42(void) { |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 47 | int x, __attribute__((unused)) y, z; |
Chris Lattner | 29e6f2b | 2008-10-20 04:57:38 +0000 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | // rdar://6096491 |
Eli Friedman | 2b680b4 | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 52 | void __attribute__((noreturn)) d0(void), __attribute__((noreturn)) d1(void); |
Chris Lattner | 29e6f2b | 2008-10-20 04:57:38 +0000 | [diff] [blame] | 53 | |
John Thompson | 5bc5cbe | 2009-11-25 22:58:06 +0000 | [diff] [blame] | 54 | void d2(void) __attribute__((noreturn)), d3(void) __attribute__((noreturn)); |
Chris Lattner | 37c75af | 2010-04-12 02:18:38 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | // PR6287 |
| 58 | void __attribute__((returns_twice)) returns_twice_test(); |
Richard Smith | b12bf69 | 2011-10-17 21:20:17 +0000 | [diff] [blame] | 59 | |
| 60 | int aligned(int); |
Richard Smith | b1f9a28 | 2013-10-31 01:56:18 +0000 | [diff] [blame] | 61 | 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}} |
Richard Smith | b12bf69 | 2011-10-17 21:20:17 +0000 | [diff] [blame] | 62 | int __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error {{expected ')'}} |
| 63 | int __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error {{expected ')'}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | |
| 67 | int testFundef1(int *a) __attribute__((nonnull(1))) { // \ |
Aaron Ballman | 6d80b3c | 2014-01-02 18:10:17 +0000 | [diff] [blame] | 68 | // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 69 | return *a; |
| 70 | } |
| 71 | |
| 72 | // noreturn is lifted to type qualifier |
| 73 | void testFundef2() __attribute__((noreturn)) { // \ |
Aaron Ballman | 6d80b3c | 2014-01-02 18:10:17 +0000 | [diff] [blame] | 74 | // expected-warning {{GCC does not allow 'noreturn' attribute in this position on a function definition}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 75 | testFundef2(); |
| 76 | } |
| 77 | |
| 78 | int testFundef3(int *a) __attribute__((nonnull(1), // \ |
Aaron Ballman | 6d80b3c | 2014-01-02 18:10:17 +0000 | [diff] [blame] | 79 | // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 80 | pure)) { // \ |
Aaron Ballman | 6d80b3c | 2014-01-02 18:10:17 +0000 | [diff] [blame] | 81 | // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 82 | return *a; |
| 83 | } |
| 84 | |
| 85 | int testFundef4(int *a) __attribute__((nonnull(1))) // \ |
Aaron Ballman | 6d80b3c | 2014-01-02 18:10:17 +0000 | [diff] [blame] | 86 | // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 87 | __attribute((pure)) { // \ |
Aaron Ballman | 6d80b3c | 2014-01-02 18:10:17 +0000 | [diff] [blame] | 88 | // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}} |
DeLesley Hutchins | 3fc6e4a | 2012-02-16 16:50:43 +0000 | [diff] [blame] | 89 | return *a; |
| 90 | } |
| 91 | |
| 92 | // GCC allows these |
| 93 | void testFundef5() __attribute__(()) { } |
| 94 | |
| 95 | __attribute__((pure)) int testFundef6(int a) { return a; } |
| 96 | |
Aaron Ballman | 35f9421 | 2014-04-14 16:03:22 +0000 | [diff] [blame] | 97 | void deprecatedTestFun(void) __attribute__((deprecated())); |
Abramo Bagnara | 152eb39 | 2014-08-16 08:29:27 +0000 | [diff] [blame] | 98 | |
| 99 | struct s { |
| 100 | int a; |
| 101 | }; |
| 102 | |
| 103 | // This test ensure compatibility with parsing GNU-style attributes |
| 104 | // where the attribute is on a separate line from the elaborated type |
| 105 | // specifier. |
| 106 | struct s |
| 107 | __attribute__((used)) bar; |