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