1 // RUN: %clang_cc1 -fsyntax-only -Wno-pragmas -verify %s
3 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(function, variable))
5 #pragma clang attribute pop
7 // Check for contradictions in rules for attribute without a strict subject set:
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}}
13 #pragma clang attribute pop
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}}
18 #pragma clang attribute pop
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}}
23 #pragma clang attribute pop
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)'}}
28 #pragma clang attribute pop
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)'
34 #pragma clang attribute pop
36 // Verify the strict subject set verification.
38 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function))
40 #pragma clang attribute pop
42 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable))
44 #pragma clang attribute pop
46 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable, record(unless(is_union))))
48 #pragma clang attribute pop
50 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union)), function))
52 #pragma clang attribute pop
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
58 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter), enum))
59 // FIXME: comma in this diagnostic is wrong.
60 // expected-error@-2 {{attribute 'abi_tag' can't be applied to 'enum_constant', and 'enum'}}
61 #pragma clang attribute pop
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
67 // Verify the non-strict subject set verification.
69 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function))
71 #pragma clang attribute pop
73 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable)
75 #pragma clang attribute pop
77 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union))))
79 #pragma clang attribute pop
81 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable))
83 #pragma clang attribute pop
85 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union))))
87 #pragma clang attribute pop
89 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function))
91 #pragma clang attribute pop
93 #pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable))
95 #pragma clang attribute pop
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'}}
101 #pragma clang attribute pop
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'}}
106 #pragma clang attribute pop
108 // Handle attributes whose subjects are supported only in other language modes:
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
114 #pragma clang attribute push(__attribute__((abi_tag("b"))), apply_to = any(namespace))
115 // 'namespace' is accepted!
116 #pragma clang attribute pop
118 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface)
120 #pragma clang attribute pop
122 #pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface)
124 #pragma clang attribute pop
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
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
134 #pragma clang attribute pop
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
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
144 #pragma clang attribute pop
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)
150 #pragma clang attribute pop
152 #pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(objc_interface, objc_protocol))
154 #pragma clang attribute pop