1 // RUN: %clang_cc1 -Wno-pragma-clang-attribute -verify -std=c++11 %s
3 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = function)
7 #pragma clang attribute pop
9 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(variable(is_parameter), function))
10 #pragma clang attribute pop
12 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = variable(unless(is_parameter)))
13 #pragma clang attribute pop
15 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(variable(unless(is_parameter))))
16 #pragma clang attribute pop
18 #pragma clang attribute push (__attribute__((abi_tag("a")))) // expected-error {{expected ','}}
19 #pragma clang attribute push (__attribute__((abi_tag("a"))) apply_to=function) // expected-error {{expected ','}}
20 #pragma clang attribute push (__attribute__((abi_tag("a"))) = function) // expected-error {{expected ','}}
21 #pragma clang attribute push (__attribute__((abi_tag("a"))) any(function)) // expected-error {{expected ','}}
23 #pragma clang attribute push (__attribute__((abi_tag("a"))) 22) // expected-error {{expected ','}}
24 #pragma clang attribute push (__attribute__((abi_tag("a"))) function) // expected-error {{expected ','}}
25 #pragma clang attribute push (__attribute__((abi_tag("a"))) (function)) // expected-error {{expected ','}}
27 #pragma clang attribute push(__attribute__((annotate("test"))), ) // expected-error {{expected attribute subject set specifier 'apply_to'}}
28 #pragma clang attribute push(__attribute__((annotate("test"))), = any(function)) // expected-error {{expected attribute subject set specifier 'apply_to'}}
29 #pragma clang attribute push(__attribute__((annotate("test"))), = function) // expected-error {{expected attribute subject set specifier 'apply_to'}}
30 #pragma clang attribute push(__attribute__((annotate("test"))), any(function)) // expected-error {{expected attribute subject set specifier 'apply_to'}}
31 #pragma clang attribute push(__attribute__((annotate("test"))), function) // expected-error {{expected attribute subject set specifier 'apply_to'}}
32 #pragma clang attribute push(__attribute__((annotate("test"))), apply = any(function )) // expected-error {{expected attribute subject set specifier 'apply_to'}}
33 #pragma clang attribute push(__attribute__((annotate("test"))), to = function) // expected-error {{expected attribute subject set specifier 'apply_to'}}
34 #pragma clang attribute push(__attribute__((annotate("test"))), apply_only_to = function) // expected-error {{expected attribute subject set specifier 'apply_to'}}
36 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to any(function)) // expected-error {{expected '='}}
37 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to function) // expected-error {{expected '='}}
38 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to) // expected-error {{expected '='}}
39 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to 41 (22)) // expected-error {{expected '='}}
40 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any) // expected-error {{expected '('}}
41 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any {) // expected-error {{expected '('}}
42 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any function) // expected-error {{expected '('}}
44 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = { function, enum }) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
46 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function ) // expected-error {{expected ')'}}
47 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, )) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
48 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, enum ) // expected-error {{expected ')'}}
50 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = () ) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
52 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( + ) ) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
53 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
54 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, 42 )) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
56 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( diag )) // expected-error {{unknown attribute subject rule 'diag'}}
57 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( a )) // expected-error {{unknown attribute subject rule 'a'}}
58 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, for)) // expected-error {{unknown attribute subject rule 'for'}}
59 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function42, for )) // expected-error {{unknown attribute subject rule 'function42'}}
61 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(hasType)) // expected-error {{expected '('}}
62 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = hasType) // expected-error {{expected '('}}
63 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = hasType(functionType)) // OK
65 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable( )) // expected-error {{expected ')'}}
66 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(variable())) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
67 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(variable(is))) // expected-error {{unknown attribute subject matcher sub-rule 'is'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
68 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is_parameter, not) )) // expected-error {{expected ')'}} expected-note {{to match this '('}}
69 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable is_parameter )) // expected-error {{expected ')'}} expected-note {{to match this '('}}
70 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable ( ) // expected-error {{expected ')'}}
71 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = variable ( // expected-error {{expected ')'}}
72 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, variable(is()))) // expected-error {{unknown attribute subject matcher sub-rule 'is'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
73 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, variable(42))) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
74 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, namespace("test") )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'namespace' matcher does not support sub-rules}}
75 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, variable ("test" )) // expected-error {{expected ')'}}
77 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = enum(is_parameter)) // expected-error {{invalid use of attribute subject matcher sub-rule 'is_parameter'; 'enum' matcher does not support sub-rules}}
78 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(enum(is_parameter))) // expected-error {{invalid use of attribute subject matcher sub-rule 'is_parameter'; 'enum' matcher does not support sub-rules}}
80 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any (function, variable (unless) )) // expected-error {{expected '('}}
81 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any (function, variable (unless() )) // expected-error {{expected ')'}}
82 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, variable(unless(is)))) // expected-error {{unknown attribute subject matcher sub-rule 'unless(is)'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
83 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter, not)) )) // expected-error {{expected ')'}} expected-note {{to match this '('}}
84 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter), not) ) // expected-error {{expected ')'}}
85 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable unless is_parameter )) // expected-error {{expected ')'}} expected-note {{to match this '('}}
86 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless is_parameter) )) // expected-error {{expected '('}}
87 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, variable(unless(42)))) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
88 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, enum(unless("test")) )) // expected-error {{expected an identifier that corresponds to an attribute subject matcher sub-rule; 'enum' matcher does not support sub-rules}}
90 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any(function, variable(unless(is_global)))) // expected-error {{unknown attribute subject matcher sub-rule 'unless(is_global)'; 'variable' matcher supports the following sub-rules: 'is_thread_local', 'is_global', 'is_local', 'is_parameter', 'unless(is_parameter)'}}
91 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( enum(unless(is_parameter)) )) // expected-error {{invalid use of attribute subject matcher sub-rule 'unless(is_parameter)'; 'enum' matcher does not support sub-rules}}
93 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, function )) // expected-error {{duplicate attribute subject matcher 'function'}}
94 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, function, function )) // expected-error 2 {{duplicate attribute subject matcher 'function'}}
95 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( function, enum, function )) // expected-error {{duplicate attribute subject matcher 'function'}}
96 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( enum, enum, function )) // expected-error {{duplicate attribute subject matcher 'enum'}}
98 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is_global), variable(is_global) )) // expected-error {{duplicate attribute subject matcher 'variable(is_global)'}}
99 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(is_global), function, variable(is_global), variable(is_global) )) // expected-error 2 {{duplicate attribute subject matcher 'variable(is_global)'}}
100 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter)), variable(unless(is_parameter)) )) // expected-error {{duplicate attribute subject matcher 'variable(unless(is_parameter))'}}
101 #pragma clang attribute push(__attribute__((annotate("test"))), apply_to = any( variable(unless(is_parameter)), variable(unless(is_parameter)), enum, variable(unless(is_parameter)) )) // expected-error 2 {{duplicate attribute subject matcher 'variable(unless(is_parameter))'}}
103 #pragma clang attribute // expected-error {{expected 'push', 'pop', or '(' after '#pragma clang attribute'}}
104 #pragma clang attribute 42 // expected-error {{expected 'push', 'pop', or '(' after '#pragma clang attribute'}}
105 #pragma clang attribute pushpop // expected-error {{expected '.' after pragma attribute namespace 'pushpop'}}
107 #pragma clang attribute push
108 #pragma clang attribute pop
109 #pragma clang attribute push ( // expected-error {{expected an attribute after '('}}
110 #pragma clang attribute push (__attribute__((annotate)) // expected-error {{expected ')'}}
111 #pragma clang attribute push () // expected-error {{expected an attribute after '('}}
113 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = function) () // expected-warning {{extra tokens at end of '#pragma clang attribute'}}
114 // expected-error@-1 {{expected unqualified-id}}
115 // expected-error@-2 {{unterminated '#pragma clang attribute push' at end of file}}
117 #pragma clang attribute pop () // expected-warning {{extra tokens at end of '#pragma clang attribute'}}
121 #pragma clang attribute push (__attribute__((42))) // expected-error {{expected identifier that represents an attribute name}}
123 #pragma clang attribute push (__attribute__((annotate)) foo) // expected-error {{expected ','}}
124 #pragma clang attribute push (__attribute__((annotate)), apply_to=function foo) // expected-error {{extra tokens after attribute in a '#pragma clang attribute push'}}
126 #pragma clang attribute push (__attribute__((objc_bridge_related)), apply_to=function)
127 // expected-error@-1 {{attribute 'objc_bridge_related' cannot be applied to 'function'}}
128 #pragma clang attribute pop
130 #pragma clang attribute push (__attribute__((objc_bridge_related(1))), apply_to=function) // expected-error {{expected a related Objective-C class name, e.g., 'NSColor'}}
132 #pragma clang attribute push (__attribute__((used)), apply_to=function) // expected-error {{attribute 'used' is not supported by '#pragma clang attribute'}}
134 void statementPragmasAndPragmaExpression() {
135 #pragma clang attribute push (__attribute__((annotate("hello"))), apply_to=variable)
136 #pragma clang attribute pop
138 _Pragma("clang attribute push (__attribute__((annotate(\"hi\"))), apply_to = function)");
140 _Pragma("clang attribute push (__attribute__((annotate(\"hi\"))), apply_to = any(function(is_method ))"); // expected-error {{expected ')'}}
143 _Pragma("clang attribute pop");
145 #pragma clang attribute push (__attribute__((address_space(0))), apply_to=variable) // expected-error {{attribute 'address_space' is not supported by '#pragma clang attribute'}}
147 // Check support for CXX11 style attributes
148 #pragma clang attribute push ([[noreturn]], apply_to = any(function))
149 #pragma clang attribute pop
151 #pragma clang attribute push ([[clang::disable_tail_calls]], apply_to = function)
152 #pragma clang attribute pop
154 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=any(function))
155 #pragma clang attribute pop
157 #pragma clang attribute push ([[gnu::abi_tag]], apply_to=namespace)
158 #pragma clang attribute pop
160 #pragma clang attribute push ([[fallthrough]], apply_to=function) // expected-error {{attribute 'fallthrough' is not supported by '#pragma clang attribute'}}
161 #pragma clang attribute push ([[clang::fallthrough]], apply_to=function) // expected-error {{attribute 'fallthrough' is not supported by '#pragma clang attribute'}}
163 #pragma clang attribute push ([[]], apply_to = function) // A noop
165 #pragma clang attribute push ([[noreturn ""]], apply_to=function) // expected-error {{expected ','}}
166 #pragma clang attribute pop
167 #pragma clang attribute push ([[noreturn 42]]) // expected-error 2 {{expected ','}}
169 #pragma clang attribute push(__attribute__, apply_to=function) // expected-error {{expected '(' after 'attribute'}}
170 #pragma clang attribute push(__attribute__(), apply_to=function) // expected-error {{expected '(' after '('}}
171 #pragma clang attribute push(__attribute__(()), apply_to=function) // expected-error {{expected identifier that represents an attribute name}}
172 #pragma clang attribute push(__attribute__((annotate, apply_to=function))) // expected-error {{expected ')'}}
173 #pragma clang attribute push(__attribute__((annotate("test"), apply_to=function))) // expected-error {{expected ')'}}
174 #pragma clang attribute push(__attribute__((annotate), apply_to=function)) // expected-error {{expected ')'}}
176 #pragma clang attribute push (42) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
177 #pragma clang attribute push (test) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
178 #pragma clang attribute push (annotate) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
179 // expected-note@-1 {{use the GNU '__attribute__' syntax}}
180 #pragma clang attribute push (annotate("test")) // expected-error {{expected an attribute that is specified using the GNU, C++11 or '__declspec' syntax}}
181 // expected-note@-1 {{use the GNU '__attribute__' syntax}}
183 #pragma clang attribute push([[clang::uninitialized]], apply_to = variable(is_local))
184 #pragma clang attribute pop
185 #pragma clang attribute push([[clang::uninitialized]], apply_to = function) // expected-error {{attribute 'uninitialized' cannot be applied to 'function'}}
186 #pragma clang attribute pop
187 #pragma clang attribute push([[clang::uninitialized]], apply_to = variable) // expected-error {{attribute 'uninitialized' cannot be applied to 'variable'}}
188 #pragma clang attribute pop
189 #pragma clang attribute push([[clang::uninitialized]], apply_to = variable(is_thread_local)) // expected-error {{attribute 'uninitialized' cannot be applied to 'variable(is_thread_local)'}}
190 #pragma clang attribute pop
191 #pragma clang attribute push([[clang::uninitialized]], apply_to = variable(is_global)) // expected-error {{attribute 'uninitialized' cannot be applied to 'variable(is_global)'}}
192 #pragma clang attribute pop
193 #pragma clang attribute push([[clang::uninitialized]], apply_to = any(variable(is_parameter), variable(unless(is_parameter)))) // expected-error {{attribute 'uninitialized' cannot be applied to 'variable(is_parameter)', and 'variable(unless(is_parameter))'}}
194 #pragma clang attribute pop
195 // We're allowed to apply attributes to subsets of allowed subjects.
196 #pragma clang attribute push([[clang::no_destroy]], apply_to = variable)
197 #pragma clang attribute pop
198 #pragma clang attribute push([[clang::no_destroy]], apply_to = variable(is_thread_local))
199 #pragma clang attribute pop
200 #pragma clang attribute push([[clang::no_destroy]], apply_to = variable(is_global))
201 #pragma clang attribute pop
202 #pragma clang attribute push([[clang::no_destroy]], apply_to = any(variable(is_parameter), variable(unless(is_parameter))))
203 #pragma clang attribute pop
205 // We explicitly do not wish to allow users to blast an attribute to everything
206 // using an unconstrained "any", so "any" must have a valid argument list.
207 #pragma clang attribute push([[clang::uninitialized]], apply_to=any) // expected-error {{expected '('}}
208 #pragma clang attribute push([[clang::uninitialized]], apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}}
209 // NB: neither of these need to be popped; they were never successfully pushed.
211 #pragma clang attribute push ([[clang::disable_tail_calls, noreturn]], apply_to = function)
212 #pragma clang attribute pop
214 #pragma clang attribute push (__attribute__((disable_tail_calls, annotate("test"))), apply_to = function)
215 #pragma clang attribute pop
217 #pragma clang attribute push (__attribute__((disable_tail_calls,)), apply_to = function) // expected-error {{expected identifier that represents an attribute name}}
219 #pragma clang attribute push ([[clang::disable_tail_calls, noreturn]]) // expected-error {{expected ','}}