mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 11:46:08 +00:00

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
29 lines
858 B
C++
29 lines
858 B
C++
// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -E %s | FileCheck %s
|
|
// RUN: %clang -fplugin=%llvmshlibdir/Attribute%pluginext -E %s -x c | FileCheck %s
|
|
// REQUIRES: plugins, examples
|
|
|
|
#ifdef __cplusplus
|
|
# define HAS_ATTR(a) __has_cpp_attribute (a)
|
|
#else
|
|
# define HAS_ATTR(a) __has_c_attribute (a)
|
|
#endif
|
|
|
|
#if __has_attribute(example)
|
|
// CHECK: has_attribute(example) was true
|
|
has_attribute(example) was true
|
|
#endif
|
|
#if HAS_ATTR(example)
|
|
// CHECK: has_$LANG_attribute(example) was true
|
|
has_$LANG_attribute(example) was true
|
|
#endif
|
|
|
|
#if __has_attribute(doesnt_exist)
|
|
// CHECK-NOT: has_attribute(doesnt_exist) unexpectedly was true
|
|
has_attribute(doesnt_exist) unexpectedly was true
|
|
#endif
|
|
|
|
#if HAS_ATTR(doesnt_exist)
|
|
// CHECK-NOT: has_$LANG_attribute(doesnt_exist) unexpectedly was true
|
|
has_$LANG_attribute(doesnt_exist) unexpectedly was true
|
|
#endif
|