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