diff options
Diffstat (limited to 'test/Sema')
-rw-r--r-- | test/Sema/alloc-align-attr.c | 6 | ||||
-rw-r--r-- | test/Sema/attr-availability.c | 2 | ||||
-rw-r--r-- | test/Sema/attr-selectany.c | 3 | ||||
-rw-r--r-- | test/Sema/pragma-attribute-strict-subjects.c | 153 | ||||
-rw-r--r-- | test/Sema/pragma-attribute.c | 47 |
5 files changed, 206 insertions, 5 deletions
diff --git a/test/Sema/alloc-align-attr.c b/test/Sema/alloc-align-attr.c index bf8591625dab2..ae514343aff4e 100644 --- a/test/Sema/alloc-align-attr.c +++ b/test/Sema/alloc-align-attr.c @@ -13,7 +13,7 @@ void *test_incorrect_param_type(float a) __attribute__((alloc_align(1))); // exp void *test_bad_param_type(void) __attribute((alloc_align(1.1))); // expected-error {{'alloc_align' attribute requires parameter 1 to be an integer constant}} // argument count -void *test_no_fn_proto() __attribute__((alloc_align)); // expected-error {{'alloc_align' attribute takes one argument}} -void *test_no_fn_proto() __attribute__((alloc_align())); // expected-error {{'alloc_align' attribute takes one argument}} -void *test_no_fn_proto() __attribute__((alloc_align(32, 45, 37))); // expected-error {{'alloc_align' attribute takes one argument}} +void *test_no_fn_proto(int x, int y) __attribute__((alloc_align)); // expected-error {{'alloc_align' attribute takes one argument}} +void *test_no_fn_proto(int x, int y) __attribute__((alloc_align())); // expected-error {{'alloc_align' attribute takes one argument}} +void *test_no_fn_proto(int x, int y) __attribute__((alloc_align(32, 45, 37))); // expected-error {{'alloc_align' attribute takes one argument}} diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c index a4b40ff9e0c30..c4133e3b9bc6e 100644 --- a/test/Sema/attr-availability.c +++ b/test/Sema/attr-availability.c @@ -74,7 +74,7 @@ extern int x; void f8() { int (^b)(int); - b = ^ (int i) __attribute__((availability(macosx,introduced=10.2))) { return 1; }; // expected-warning {{'availability' attribute ignored}} + b = ^ (int i) __attribute__((availability(macosx,introduced=10.2))) { return 1; }; // expected-warning {{'availability' attribute only applies to named declarations}} } extern int x2 __attribute__((availability(macosx,introduced=10.2))); // expected-note {{previous attribute is here}} diff --git a/test/Sema/attr-selectany.c b/test/Sema/attr-selectany.c index 01cca7d7cfa52..9fa2fcade539f 100644 --- a/test/Sema/attr-selectany.c +++ b/test/Sema/attr-selectany.c @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fms-compatibility -fms-extensions -verify %s +// RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s +// RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s extern __declspec(selectany) const int x1 = 1; // no warning, const means we need extern in C++ diff --git a/test/Sema/pragma-attribute-strict-subjects.c b/test/Sema/pragma-attribute-strict-subjects.c new file mode 100644 index 0000000000000..a84e2bde38d5d --- /dev/null +++ b/test/Sema/pragma-attribute-strict-subjects.c @@ -0,0 +1,153 @@ +// RUN: %clang_cc1 -fsyntax-only -Wno-pragmas -verify %s + +#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(function, variable)) + +#pragma clang attribute pop + +// Check for contradictions in rules for attribute without a strict subject set: + +#pragma clang attribute push (__attribute__((annotate("subRuleContradictions"))), apply_to = any(variable, variable(is_parameter), function(is_member), variable(is_global))) +// expected-error@-1 {{redundant attribute subject matcher sub-rule 'variable(is_parameter)'; 'variable' already matches those declarations}} +// expected-error@-2 {{redundant attribute subject matcher sub-rule 'variable(is_global)'; 'variable' already matches those declarations}} + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((annotate("subRuleContradictions2"))), apply_to = any(function(is_member), function)) +// expected-error@-1 {{redundant attribute subject matcher sub-rule 'function(is_member)'; 'function' already matches those declarations}} + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((annotate("subRuleContradictions3"))), apply_to = any(variable, variable(unless(is_parameter)))) +// expected-error@-1 {{redundant attribute subject matcher sub-rule 'variable(unless(is_parameter))'; 'variable' already matches those declarations}} + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((annotate("negatedSubRuleContradictions1"))), apply_to = any(variable(is_parameter), variable(unless(is_parameter)))) +// expected-error@-1 {{negated attribute subject matcher sub-rule 'variable(unless(is_parameter))' contradicts sub-rule 'variable(is_parameter)'}} + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((annotate("negatedSubRuleContradictions2"))), apply_to = any(variable(unless(is_parameter)), variable(is_thread_local), function, variable(is_global))) +// expected-error@-1 {{negated attribute subject matcher sub-rule 'variable(unless(is_parameter))' contradicts sub-rule 'variable(is_global)'}} +// We have just one error, don't error on 'variable(is_global)' + +#pragma clang attribute pop + +// Verify the strict subject set verification. + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function)) +// No error +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable)) +// No error +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable, record(unless(is_union)))) +// No error +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union)), function)) +// No error +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), variable, enum)) +// expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}} +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(enum_constant, function, record(unless(is_union)), variable, variable(is_parameter))) +// expected-error@-1 {{attribute 'abi_tag' can't be applied to 'variable(is_parameter)', and 'enum_constant'}} +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, record(unless(is_union)), enum)) +// expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}} +#pragma clang attribute pop + +// Verify the non-strict subject set verification. + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function)) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = variable) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)))) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(function, variable)) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(variable, record(unless(is_union)))) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function)) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable)) + +#pragma clang attribute pop + + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = any(record(unless(is_union)), function, variable, enum, enum_constant)) +// expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum_constant', and 'enum'}} + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = enum) +// expected-error@-1 {{attribute 'abi_tag' can't be applied to 'enum'}} + +#pragma clang attribute pop + +// Handle attributes whose subjects are supported only in other language modes: + +#pragma clang attribute push(__attribute__((abi_tag("b"))), apply_to = any(namespace, record(unless(is_union)), variable, function)) +// 'namespace' is accepted! +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((abi_tag("b"))), apply_to = any(namespace)) +// 'namespace' is accepted! +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface) +// No error! +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = objc_interface) +// No error! +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_interface, objc_protocol)) +// expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}} +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_protocol)) +// expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}} +// Don't report an error about missing 'objc_interface' as we aren't parsing +// Objective-C. +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_interface, objc_protocol)) +// expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}} +#pragma clang attribute pop + +#pragma clang attribute push(__attribute__((objc_subclassing_restricted)), apply_to = any(objc_protocol)) +// expected-error@-1 {{attribute 'objc_subclassing_restricted' can't be applied to 'objc_protocol'}} +// Don't report an error about missing 'objc_interface' as we aren't parsing +// Objective-C. +#pragma clang attribute pop + +// Use of matchers from other language modes should not cause for attributes +// without subject list: +#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = objc_method) + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((annotate("test"))), apply_to = any(objc_interface, objc_protocol)) + +#pragma clang attribute pop diff --git a/test/Sema/pragma-attribute.c b/test/Sema/pragma-attribute.c new file mode 100644 index 0000000000000..d321f2ce4be76 --- /dev/null +++ b/test/Sema/pragma-attribute.c @@ -0,0 +1,47 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +#pragma clang attribute pop // expected-error {{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}} + +// Don't verify unused attributes. +#pragma clang attribute push (__attribute__((annotate)), apply_to = function) // expected-warning {{unused attribute 'annotate' in '#pragma clang attribute push' region}} +#pragma clang attribute pop // expected-note {{'#pragma clang attribute push' regions ends here}} + +// Ensure we only report any errors once. +#pragma clang attribute push (__attribute__((annotate)), apply_to = function) // expected-error 4 {{'annotate' attribute takes one argument}} + +void test5_begin(); // expected-note {{when applied to this declaration}} +void test5_1(); // expected-note {{when applied to this declaration}} + +#pragma clang attribute push (__attribute__((annotate())), apply_to = function) // expected-error 2 {{'annotate' attribute takes one argument}} + +void test5_2(); // expected-note 2 {{when applied to this declaration}} + +#pragma clang attribute push (__attribute__((annotate("hello", "world"))), apply_to = function) // expected-error {{'annotate' attribute takes one argument}} + +void test5_3(); // expected-note 3 {{when applied to this declaration}} + +#pragma clang attribute pop +#pragma clang attribute pop +#pragma clang attribute pop + +// Verify that the warnings are reported for each receiver declaration + +#pragma clang attribute push (__attribute__((optnone)), apply_to = function) // expected-note 2 {{conflicting attribute is here}} + +__attribute__((always_inline)) void optnone1() { } // expected-warning {{'always_inline' attribute ignored}} +// expected-note@-1 {{when applied to this declaration}} + +void optnone2() { } + +__attribute__((always_inline)) void optnone3() { } // expected-warning {{'always_inline' attribute ignored}} +// expected-note@-1 {{when applied to this declaration}} + +#pragma clang attribute pop + +#pragma clang attribute push ([[]], apply_to = function) // A noop + +#pragma clang attribute pop // expected-error {{'#pragma clang attribute pop' with no matching '#pragma clang attribute push'}} + +#pragma clang attribute push (__attribute__((annotate("func"))), apply_to = function) // expected-error {{unterminated '#pragma clang attribute push' at end of file}} + +void function(); |