Author: Aaron Ballman Date: 2021-11-17T08:24:26-05:00 New Revision: 3874277f415dca0bb222956983f117a6211c0e39
URL: https://github.com/llvm/llvm-project/commit/3874277f415dca0bb222956983f117a6211c0e39 DIFF: https://github.com/llvm/llvm-project/commit/3874277f415dca0bb222956983f117a6211c0e39.diff LOG: Improve docs & test for #pragma clang attribute's any clause; NFC There was some confusion during the discussion of a patch as to whether `any` can be used to blast an attribute with no subject list onto basically everything in a program by not specifying a subrule. This patch adds documentation and tests to make it clear that this situation is not supported and will be diagnosed. Added: Modified: clang/docs/LanguageExtensions.rst clang/test/Parser/pragma-attribute.cpp Removed: ################################################################################ diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 8f7727e27bf60..60b1ed383a1ff 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -3798,7 +3798,8 @@ Multiple match rules can be specified using the ``any`` match rule, as shown in the example above. The ``any`` rule applies attributes to all declarations that are matched by at least one of the rules in the ``any``. It doesn't nest and can't be used inside the other match rules. Redundant match rules or rules -that conflict with one another should not be used inside of ``any``. +that conflict with one another should not be used inside of ``any``. Failing to +specify a rule within the ``any`` rule results in an error. Clang supports the following match rules: diff --git a/clang/test/Parser/pragma-attribute.cpp b/clang/test/Parser/pragma-attribute.cpp index d51f8159c263c..d82eaa3f01b0f 100644 --- a/clang/test/Parser/pragma-attribute.cpp +++ b/clang/test/Parser/pragma-attribute.cpp @@ -204,3 +204,9 @@ _Pragma("clang attribute pop"); #pragma clang attribute pop #pragma clang attribute push([[clang::no_destroy]], apply_to = any(variable(is_parameter), variable(unless(is_parameter)))) #pragma clang attribute pop + +// We explicitly do not wish to allow users to blast an attribute to everything +// using an unconstrained "any", so "any" must have a valid argument list. +#pragma clang attribute push([[clang::uninitialized]], apply_to=any) // expected-error {{expected '('}} +#pragma clang attribute push([[clang::uninitialized]], apply_to = any()) // expected-error {{expected an identifier that corresponds to an attribute subject rule}} +// NB: neither of these need to be popped; they were never successfully pushed. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits