1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s -pedantic -std=c99
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanint __attribute__(()) x;
47399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
5eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedman__inline void __attribute__((__always_inline__, __nodebug__))
67399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattnerfoo(void) {
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
87399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
97399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
10eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedman__attribute__(()) y;   // expected-warning {{defaults to 'int'}}
117399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
127399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner// PR2796
13eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanint (__attribute__(()) *z)(long y);
147399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
157399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
16eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid f1(__attribute__(()) int x);
177399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
18eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanint f2(y, __attribute__(()) x);     // expected-error {{expected identifier}}
197399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
207399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner// This is parsed as a normal argument list (with two args that are implicit
21eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedman// int) because the __attribute__ is a declspec.
22eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid f3(__attribute__(()) x,  // expected-warning {{defaults to 'int'}}
237399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner        y);               // expected-warning {{defaults to 'int'}}
247399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
25eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid f4(__attribute__(()));   // expected-error {{expected parameter declarator}}
267399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
277399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
28eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedman// This is ok, the __attribute__ applies to the pointer.
29eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanint baz(int (__attribute__(()) *x)(long y));
307399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
31eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid g1(void (*f1)(__attribute__(()) int x));
32eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid g2(int (*f2)(y, __attribute__(()) x));    // expected-error {{expected identifier}}
33eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid g3(void (*f3)(__attribute__(()) x, int y));  // expected-warning {{defaults to 'int'}}
34eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid g4(void (*f4)(__attribute__(())));  // expected-error {{expected parameter declarator}}
357399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
367399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
37eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid (*h1)(void (*f1)(__attribute__(()) int x));
38eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid (*h2)(int (*f2)(y, __attribute__(()) x));    // expected-error {{expected identifier}}
397399ee0aa6ffaeab0a8f83408b1c5127fb2bf5b8Chris Lattner
40eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid (*h3)(void (*f3)(__attribute__(()) x));   // expected-warning {{defaults to 'int'}}
41eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid (*h4)(void (*f4)(__attribute__(())));  // expected-error {{expected parameter declarator}}
42aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner
43aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner
44aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner
45aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner// rdar://6131260
46aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattnerint foo42(void) {
47eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedman  int x, __attribute__((unused)) y, z;
48aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner  return 0;
49aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner}
50aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner
51aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner// rdar://6096491
52eb32fde032a250091134db56a3aeaea6b09f6594Eli Friedmanvoid __attribute__((noreturn)) d0(void), __attribute__((noreturn)) d1(void);
53aab740af64daaa8d94d34789a6ea7e2d2fc5ab39Chris Lattner
541b2fc0f3e181d99fb34f60e711066fb11628ecd0John Thompsonvoid d2(void) __attribute__((noreturn)), d3(void) __attribute__((noreturn));
55e8551e4abd314053b45f10f22fa69fb6f8e8b449Chris Lattner
56e8551e4abd314053b45f10f22fa69fb6f8e8b449Chris Lattner
57e8551e4abd314053b45f10f22fa69fb6f8e8b449Chris Lattner// PR6287
58e8551e4abd314053b45f10f22fa69fb6f8e8b449Chris Lattnervoid __attribute__((returns_twice)) returns_twice_test();
59fe0a0fb65f18a8495d97a700ca62fe639ffd85e9Richard Smith
60fe0a0fb65f18a8495d97a700ca62fe639ffd85e9Richard Smithint aligned(int);
61d386fef64f1fd00fc9a97efb963d8ec393fd1aceRichard Smithint __attribute__((vec_type_hint(char, aligned(16) )) missing_rparen_1; // expected-error 2{{expected ')'}} expected-note {{to match}} expected-warning {{does not declare anything}}
62fe0a0fb65f18a8495d97a700ca62fe639ffd85e9Richard Smithint __attribute__((mode(x aligned(16) )) missing_rparen_2; // expected-error {{expected ')'}}
63fe0a0fb65f18a8495d97a700ca62fe639ffd85e9Richard Smithint __attribute__((format(printf, 0 aligned(16) )) missing_rparen_3; // expected-error {{expected ')'}}
64c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
65c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
66c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
67c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchinsint testFundef1(int *a) __attribute__((nonnull(1))) { // \
68651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
69c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  return *a;
70c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins}
71c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
72c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins// noreturn is lifted to type qualifier
73c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchinsvoid testFundef2() __attribute__((noreturn)) { // \
74651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    // expected-warning {{GCC does not allow 'noreturn' attribute in this position on a function definition}}
75c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  testFundef2();
76c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins}
77c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
78c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchinsint testFundef3(int *a) __attribute__((nonnull(1), // \
79651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
80c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins                                     pure)) { // \
81651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
82c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  return *a;
83c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins}
84c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
85c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchinsint testFundef4(int *a) __attribute__((nonnull(1))) // \
86651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    // expected-warning {{GCC does not allow 'nonnull' attribute in this position on a function definition}}
87c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins                      __attribute((pure)) { // \
88651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    // expected-warning {{GCC does not allow 'pure' attribute in this position on a function definition}}
89c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins  return *a;
90c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins}
91c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
92c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins// GCC allows these
93c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchinsvoid testFundef5() __attribute__(()) { }
94c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
95c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins__attribute__((pure)) int testFundef6(int a) { return a; }
96c24a2335677f3d1bd2cab1019ac445d650f52123DeLesley Hutchins
976bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesvoid deprecatedTestFun(void) __attribute__((deprecated()));
98