From 1285a495d5886b99f8d193c90b258a56f89c8937 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Sun, 12 Feb 2023 22:12:08 +0100 Subject: [clang][pp] Handle attributes defined by plugin in __has_attribute When using attributes by plugins (both in clang and clang-tidy) the preprocessor functions `__has_attribute`, `__has_c_attribute`, `__has_cpp_attribute` still returned 0. That problem is fixed by having the "hasAttribute" function also check if any of the plugins provide that attribute. This also adds C2x spelling to the example plugin for attributes so that `__has_c_attribute` can be tested. Differential Revision: https://reviews.llvm.org/D144405 --- clang/examples/Attribute/Attribute.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'clang/examples') diff --git a/clang/examples/Attribute/Attribute.cpp b/clang/examples/Attribute/Attribute.cpp index 159b09e..24b95dd 100644 --- a/clang/examples/Attribute/Attribute.cpp +++ b/clang/examples/Attribute/Attribute.cpp @@ -9,6 +9,8 @@ // Example clang plugin which adds an an annotation to file-scope declarations // with the 'example' attribute. // +// This plugin is used by clang/test/Frontend/plugin-attribute tests. +// //===----------------------------------------------------------------------===// #include "clang/AST/ASTContext.h" @@ -27,9 +29,10 @@ struct ExampleAttrInfo : public ParsedAttrInfo { // number of arguments. This just illustrates how many arguments a // `ParsedAttrInfo` can hold, we will not use that much in this example. OptArgs = 15; - // GNU-style __attribute__(("example")) and C++-style [[example]] and + // GNU-style __attribute__(("example")) and C++/C2x-style [[example]] and // [[plugin::example]] supported. static constexpr Spelling S[] = {{ParsedAttr::AS_GNU, "example"}, + {ParsedAttr::AS_C2x, "example"}, {ParsedAttr::AS_CXX11, "example"}, {ParsedAttr::AS_CXX11, "plugin::example"}}; Spellings = S; -- cgit v1.1