155 lines · c
1// RUN: %clang_cc1 -fsyntax-only -Wno-pragmas -verify %s2 3#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(function, variable))4 5#pragma clang attribute pop6 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 pop14 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 pop19 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 pop24 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 pop29 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 pop35 36// Verify the strict subject set verification.37 38#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function))39// No error40#pragma clang attribute pop41 42#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable))43// No error44#pragma clang attribute pop45 46#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable, record(unless(is_union))))47// No error48#pragma clang attribute pop49 50#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union)), function))51// No error52#pragma clang attribute pop53 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' cannot be applied to 'enum'}}56#pragma clang attribute pop57 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' cannot be applied to 'enum_constant', and 'enum'}}61#pragma clang attribute pop62 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' cannot be applied to 'enum'}}65#pragma clang attribute pop66 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 pop72 73#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable)74 75#pragma clang attribute pop76 77#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union))))78 79#pragma clang attribute pop80 81#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable))82 83#pragma clang attribute pop84 85#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union))))86 87#pragma clang attribute pop88 89#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function))90 91#pragma clang attribute pop92 93#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable))94 95#pragma clang attribute pop96 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' cannot be applied to 'enum_constant', and 'enum'}}100 101#pragma clang attribute pop102 103#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = enum)104// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}}105 106#pragma clang attribute pop107 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 pop113 114#pragma clang attribute push(__attribute__((abi_tag("b"))), apply_to = any(namespace))115// 'namespace' is accepted!116#pragma clang attribute pop117 118#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface)119// No error!120#pragma clang attribute pop121 122#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface)123// No error!124#pragma clang attribute pop125 126#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_interface, objc_protocol))127// expected-error@-1 {{attribute 'objc_subclassing_restricted' cannot be applied to 'objc_protocol'}}128#pragma clang attribute pop129 130#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_protocol))131// expected-error@-1 {{attribute 'objc_subclassing_restricted' cannot be applied to 'objc_protocol'}}132// Don't report an error about missing 'objc_interface' as we aren't parsing133// Objective-C.134#pragma clang attribute pop135 136#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_interface, objc_protocol))137// expected-error@-1 {{attribute 'objc_subclassing_restricted' cannot be applied to 'objc_protocol'}}138#pragma clang attribute pop139 140#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_protocol))141// expected-error@-1 {{attribute 'objc_subclassing_restricted' cannot be applied to 'objc_protocol'}}142// Don't report an error about missing 'objc_interface' as we aren't parsing143// Objective-C.144#pragma clang attribute pop145 146// Use of matchers from other language modes should not cause for attributes147// without subject list:148#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = objc_method)149 150#pragma clang attribute pop151 152#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(objc_interface, objc_protocol))153 154#pragma clang attribute pop155