1 // RUN: %clang_cc1 -fsyntax-only -Wno-pragmas -verify %s
2 
3 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(function, variable))
4 
5 #pragma clang attribute pop
6 
7 // Check for contradictions in rules for attribute without a strict subject set:
8 
9 #pragma clang attribute push (__attribute__((annotate("subRuleContradictions"))), apply_to = any(variable, variable(is_parameter), function(is_member), variable(is_global)))
10 // expected-error@-1 {{redundant attribute subject matcher sub-rule 'variable(is_parameter)'; 'variable' already matches those declarations}}
11 // expected-error@-2 {{redundant attribute subject matcher sub-rule 'variable(is_global)'; 'variable' already matches those declarations}}
12 
13 #pragma clang attribute pop
14 
15 #pragma clang attribute push (__attribute__((annotate("subRuleContradictions2"))), apply_to = any(function(is_member), function))
16 // expected-error@-1 {{redundant attribute subject matcher sub-rule 'function(is_member)'; 'function' already matches those declarations}}
17 
18 #pragma clang attribute pop
19 
20 #pragma clang attribute push (__attribute__((annotate("subRuleContradictions3"))), apply_to = any(variable, variable(unless(is_parameter))))
21 // expected-error@-1 {{redundant attribute subject matcher sub-rule 'variable(unless(is_parameter))'; 'variable' already matches those declarations}}
22 
23 #pragma clang attribute pop
24 
25 #pragma clang attribute push (__attribute__((annotate("negatedSubRuleContradictions1"))), apply_to = any(variable(is_parameter), variable(unless(is_parameter))))
26 // expected-error@-1 {{negated attribute subject matcher sub-rule 'variable(unless(is_parameter))' contradicts sub-rule 'variable(is_parameter)'}}
27 
28 #pragma clang attribute pop
29 
30 #pragma clang attribute push (__attribute__((annotate("negatedSubRuleContradictions2"))), apply_to = any(variable(unless(is_parameter)), variable(is_thread_local), function, variable(is_global)))
31 // expected-error@-1 {{negated attribute subject matcher sub-rule 'variable(unless(is_parameter))' contradicts sub-rule 'variable(is_global)'}}
32 // We have just one error, don't error on 'variable(is_global)'
33 
34 #pragma clang attribute pop
35 
36 // Verify the strict subject set verification.
37 
38 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function))
39 // No error
40 #pragma clang attribute pop
41 
42 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable))
43 // No error
44 #pragma clang attribute pop
45 
46 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable, record(unless(is_union))))
47 // No error
48 #pragma clang attribute pop
49 
50 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union)), function))
51 // No error
52 #pragma clang attribute pop
53 
54 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum))
55 // expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}}
56 #pragma clang attribute pop
57 
58 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter)))
59 // FIXME: comma in this diagnostic is wrong.
60 // expected-error@-2 {{attribute 'abi_tag' can't be applied to 'enum_constant', and 'variable(is_parameter)'}}
61 #pragma clang attribute pop
62 
63 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), enum))
64 // expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}}
65 #pragma clang attribute pop
66 
67 // Verify the non-strict subject set verification.
68 
69 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function))
70 
71 #pragma clang attribute pop
72 
73 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable)
74 
75 #pragma clang attribute pop
76 
77 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union))))
78 
79 #pragma clang attribute pop
80 
81 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable))
82 
83 #pragma clang attribute pop
84 
85 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union))))
86 
87 #pragma clang attribute pop
88 
89 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function))
90 
91 #pragma clang attribute pop
92 
93 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable))
94 
95 #pragma clang attribute pop
96 
97 
98 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable, enum, enum_constant))
99 // expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum_constant', and 'enum'}}
100 
101 #pragma clang attribute pop
102 
103 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = enum)
104 // expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}}
105 
106 #pragma clang attribute pop
107 
108 // Handle attributes whose subjects are supported only in other language modes:
109 
110 #pragma clang attribute push(__attribute__((abi_tag("b"))), apply_to = any(namespace, record(unless(is_union)), variable, function))
111 // 'namespace' is accepted!
112 #pragma clang attribute pop
113 
114 #pragma clang attribute push(__attribute__((abi_tag("b"))), apply_to = any(namespace))
115 // 'namespace' is accepted!
116 #pragma clang attribute pop
117 
118 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface)
119 // No error!
120 #pragma clang attribute pop
121 
122 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface)
123 // No error!
124 #pragma clang attribute pop
125 
126 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_interface, objc_protocol))
127 // expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}}
128 #pragma clang attribute pop
129 
130 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_protocol))
131 // expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}}
132 // Don't report an error about missing 'objc_interface' as we aren't parsing
133 // Objective-C.
134 #pragma clang attribute pop
135 
136 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_interface, objc_protocol))
137 // expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}}
138 #pragma clang attribute pop
139 
140 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_protocol))
141 // expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}}
142 // Don't report an error about missing 'objc_interface' as we aren't parsing
143 // Objective-C.
144 #pragma clang attribute pop
145 
146 // Use of matchers from other language modes should not cause for attributes
147 // without subject list:
148 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = objc_method)
149 
150 #pragma clang attribute pop
151 
152 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(objc_interface, objc_protocol))
153 
154 #pragma clang attribute pop
155