aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/Attributes.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-09-18[clang] Don't include StringSwitch.h (NFC)Kazu Hirata1-1/+0
These files don't seem to use StringSwitch.
2022-06-03[Attributes] Remove AttrSyntax and migrate uses to ↵Leonard Grey1-3/+3
AttributeCommonInfo::Syntax (NFC) This is setup for allowing hasAttribute to work for plugin-provided attributes Differential Revision: https://reviews.llvm.org/D126902
2022-06-02Support warn_unused_result on typedefsDavid Blaikie1-0/+4
While it's not as robust as using the attribute on enums/classes (the type information may be lost through a function pointer, a declaration or use of the underlying type without using the typedef, etc) but I think there's still value in being able to attribute a typedef and have all return types written with that typedef pick up the warn_unused_result behavior. Specifically I'd like to be able to annotate LLVMErrorRef (a wrapper for llvm::Error used in the C API - the underlying type is a raw pointer, so it can't be attributed itself) to reduce the chance of unhandled errors. Differential Revision: https://reviews.llvm.org/D102122
2021-07-12[OpenMP] Support OpenMP 5.1 attributesAaron Ballman1-0/+8
OpenMP 5.1 added support for writing OpenMP directives using [[]] syntax in addition to using #pragma and this introduces support for the new syntax. In OpenMP, the attributes take one of two forms: [[omp::directive(...)]] or [[omp::sequence(...)]]. A directive attribute contains an OpenMP directive clause that is identical to the analogous #pragma syntax. A sequence attribute can contain either sequence or directive arguments and is used to ensure that the attributes are processed sequentially for situations where the order of the attributes matter (remember: https://eel.is/c++draft/dcl.attr.grammar#4.sentence-4). The approach taken here is somewhat novel and deserves mention. We could refactor much of the OpenMP parsing logic to work for either pragma annotation tokens or for attribute clauses. It would be a fair amount of effort to share the logic for both, but it's certainly doable. However, the semantic attribute system is not designed to handle the arbitrarily complex arguments that OpenMP directives contain. Adding support to thread the novel parsed information until we can produce a semantic attribute would be considerably more effort. What's more, existing OpenMP constructs are not (often) represented as semantic attributes. So doing this through Attr.td would be a massive undertaking that would likely only benefit OpenMP and comes with additional risks. Rather than walk down that path, I am taking advantage of the fact that the syntax of the directives within the directive clause is identical to that of the #pragma form. Once the parser recognizes that we're processing an OpenMP attribute, it caches all of the directive argument tokens and then replays them as though the user wrote a pragma. This reuses the same OpenMP parsing and semantic logic directly, but does come with a risk if the OpenMP committee decides to purposefully diverge their pragma and attribute syntaxes. So, despite this being a novel approach that does token replay, I think it's actually a better approach than trying to do this through the declarative syntax in Attr.td.
2020-03-25Build fix: AttributeCommonInfo::AS_C2xHans Wennborg1-1/+1
2020-03-25Don't normalise CXX11/C2X attribute names to start with ::John Brawn1-4/+4
Currently square-bracket-style (CXX11/C2X) attribute names are normalised to start with :: if they don't have a namespace. This is a bit odd, as such names are rejected when parsing, so don't do this. Differential Revision: https://reviews.llvm.org/D76704
2020-02-27Add an attribute registry so plugins can add attributesJohn Brawn1-19/+30
When constructing a ParsedAttr the ParsedAttrInfo gets looked up in the AttrInfoMap, which is auto-generated using tablegen. If that lookup fails then we look through the ParsedAttrInfos that plugins have added to the registry and check if any has a spelling that matches. Differential Revision: https://reviews.llvm.org/D31338
2019-09-16Move some definitions from Sema to Basic to fix shared libs buildErich Keane1-1/+74
r371875 moved some functionality around to a Basic header file, but didn't move its definitions as well. This patch moves some things around so that shared library building can work. llvm-svn: 371985
2018-11-09Introduce the _Clang scoped attribute token.Aaron Ballman1-10/+12
Currently, we only accept clang as the scoped attribute identifier for double square bracket attributes provided by Clang, but this has the potential to conflict with user-defined macros. To help alleviate these concerns, this introduces the _Clang scoped attribute identifier as an alias for clang. It also introduces a warning with a fixit on the off chance someone attempts to use __clang__ as the scoped attribute (which is a predefined compiler identification macro). llvm-svn: 346521
2018-10-24Support accepting __gnu__ as a scoped attribute namespace that aliases to gnu.Aaron Ballman1-6/+11
This is useful in libstdc++ to avoid clashes with identifiers in the user's namespace. llvm-svn: 345132
2017-04-18Add #pragma clang attributeAlex Lorenz1-0/+11
This is a recommit of r300539 that was reverted in r300543 due to test failures. The original commit message is displayed below: The new '#pragma clang attribute' directive can be used to apply attributes to multiple declarations. An attribute must satisfy the following conditions to be supported by the pragma: - It must have a subject list that's defined in the TableGen file. - It must be documented. - It must not be late parsed. - It must have a GNU/C++11 spelling. Differential Revision: https://reviews.llvm.org/D30009 llvm-svn: 300556
2017-04-18Revert r300539 - Add #pragma clang attributeAlex Lorenz1-11/+0
Some tests fail on the Windows buildbots. I will have to investigate more. This commit reverts r300539, r300540 and r300542. llvm-svn: 300543
2017-04-18Add #pragma clang attributeAlex Lorenz1-0/+11
The new '#pragma clang attribute' directive can be used to apply attributes to multiple declarations. An attribute must satisfy the following conditions to be supported by the pragma: - It must have a subject list that's defined in the TableGen file. - It must be documented. - It must not be late parsed. - It must have a GNU/C++11 spelling. Differential Revision: https://reviews.llvm.org/D30009 llvm-svn: 300539
2015-07-20Ignore the "novtable" declspec when not using the Microsoft C++ ABI.Bob Wilson1-2/+2
Clang used to silently ignore __declspec(novtable). It is implemented now, but leaving the vtable uninitialized does not work when using the Itanium ABI, where the class layout for complex class hierarchies is stored in the vtable. It might be possible to honor the novtable attribute in some simple cases and either report an error or ignore it in more complex situations, but it’s not clear if that would be worthwhile. There is also value in having a simple and predictable behavior, so this changes clang to simply ignore novtable when not using the Microsoft C++ ABI. llvm-svn: 242730
2014-11-14Complete support for the SD-6 standing document (based off N4200) with ↵Aaron Ballman1-2/+2
support for __has_cpp_attribute. llvm-svn: 221991
2014-03-31Post-commit review coding style change: renaming HasAttribute to ↵Aaron Ballman1-1/+1
hasAttribute. No functional changes. llvm-svn: 205201
2014-03-31Reapplying r204952 a second time.Aaron Ballman1-0/+17
Clean up the __has_attribute implementation without modifying its behavior. Replaces the tablegen-driven AttrSpellings.inc, which lived in the lexing layer with AttrHasAttributeImpl.inc, which lives in the basic layer. Updates the preprocessor to call through to this new functionality which can take additional information into account (such as scopes and syntaxes). Expose the ability for parts of the compiler to ask whether an attribute is supported for a given spelling (including scope), syntax, triple and language options. llvm-svn: 205181
2014-03-27Reverting r204968 and r204969; while more build bots are happy with the ↵Aaron Ballman1-17/+0
results, some still have link errors. llvm-svn: 204974
2014-03-27Reapplying r204952 with fixes which should hopefully resolve linking issues ↵Aaron Ballman1-0/+17
with non-MSVC compilers. llvm-svn: 204968
2014-03-27Reverting r204952, while I figure out what's going on with the makefile build.Aaron Ballman1-20/+0
llvm-svn: 204955
2014-03-27Clean up the __has_attribute implementation without modifying its behavior. Aaron Ballman1-0/+20
Replaces the tablegen-driven AttrSpellings.inc, which lived in the lexing layer with AttrHasAttributeImpl.inc, which lives in the basic layer. Updates the preprocessor to call through to this new functionality which can take additional information into account (such as scopes and syntaxes). Expose the ability for parts of the compiler to ask whether an attribute is supported for a given spelling (including scope), syntax, triple and language options. llvm-svn: 204952