aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-07-23 09:50:15 +0200
committerJakub Jelinek <jakub@redhat.com>2021-07-23 09:50:15 +0200
commit7f7364108f7441e6bd6f6f79a2d991e4e0f71b28 (patch)
tree2be09c88daca7fffbe70c1f7dcafa99e168efe23 /gcc
parent2c5d803d03209478b4f060785c6f6ba2f0de88ad (diff)
downloadgcc-7f7364108f7441e6bd6f6f79a2d991e4e0f71b28.zip
gcc-7f7364108f7441e6bd6f6f79a2d991e4e0f71b28.tar.gz
gcc-7f7364108f7441e6bd6f6f79a2d991e4e0f71b28.tar.bz2
openmp: Add support for __has_attribute(omp::directive) and __has_attribute(omp::sequence)
Now that the C++ FE supports these attributes, but not through registering them in the attributes tables (they work quite differently from other attributes), this teaches c_common_has_attributes about those. 2021-07-23 Jakub Jelinek <jakub@redhat.com> * c-lex.c (c_common_has_attribute): Call canonicalize_attr_name also on attr_id. Return 1 for omp::directive or omp::sequence in C++11 and later. * c-c++-common/gomp/attrs-1.c: New test. * c-c++-common/gomp/attrs-2.c: New test. * c-c++-common/gomp/attrs-3.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/c-lex.c15
-rw-r--r--gcc/testsuite/c-c++-common/gomp/attrs-1.c146
-rw-r--r--gcc/testsuite/c-c++-common/gomp/attrs-2.c146
-rw-r--r--gcc/testsuite/c-c++-common/gomp/attrs-3.c74
4 files changed, 380 insertions, 1 deletions
diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c
index c44e7a1..4b04e71 100644
--- a/gcc/c-family/c-lex.c
+++ b/gcc/c-family/c-lex.c
@@ -338,7 +338,20 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
tree attr_id
= get_identifier ((const char *)
cpp_token_as_text (pfile, nxt_token));
- attr_name = build_tree_list (attr_ns, attr_id);
+ attr_id = canonicalize_attr_name (attr_id);
+ if (c_dialect_cxx ())
+ {
+ /* OpenMP attributes need special handling. */
+ if ((flag_openmp || flag_openmp_simd)
+ && is_attribute_p ("omp", attr_ns)
+ && (is_attribute_p ("directive", attr_id)
+ || is_attribute_p ("sequence", attr_id)))
+ result = 1;
+ }
+ if (result)
+ attr_name = NULL_TREE;
+ else
+ attr_name = build_tree_list (attr_ns, attr_id);
}
else
{
diff --git a/gcc/testsuite/c-c++-common/gomp/attrs-1.c b/gcc/testsuite/c-c++-common/gomp/attrs-1.c
new file mode 100644
index 0000000..e3c0fa6
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/attrs-1.c
@@ -0,0 +1,146 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+#if __has_attribute(omp::directive)
+#ifndef __cplusplus
+#error omp::directive supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::directive not supported in C++
+#endif
+#endif
+
+#if __has_attribute(omp::sequence)
+#ifndef __cplusplus
+#error omp::sequence supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::sequence not supported in C++
+#endif
+#endif
+
+#if __has_attribute(omp::unknown)
+#error omp::unknown supported
+#endif
+
+#if __has_cpp_attribute(omp::directive)
+#ifndef __cplusplus
+#error omp::directive supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::directive not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(omp::sequence)
+#ifndef __cplusplus
+#error omp::sequence supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::sequence not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(omp::unknown)
+#error omp::unknown supported
+#endif
+
+#if __has_attribute(__omp__::__directive__)
+#ifndef __cplusplus
+#error __omp__::__directive__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__directive__ not supported in C++
+#endif
+#endif
+
+#if __has_attribute(__omp__::__sequence__)
+#ifndef __cplusplus
+#error __omp__::__sequence__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__sequence__ not supported in C++
+#endif
+#endif
+
+#if __has_attribute(__omp__::__unknown__)
+#error __omp__::__unknown__ supported
+#endif
+
+#if __has_cpp_attribute(__omp__::__directive__)
+#ifndef __cplusplus
+#error __omp__::__directive__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__directive__ not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(__omp__::__sequence__)
+#ifndef __cplusplus
+#error __omp__::__sequence__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__sequence__ not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(__omp__::__unknown__)
+#error __omp__::__unknown__ supported
+#endif
+
+#if __has_attribute(omp::__directive__)
+#ifndef __cplusplus
+#error omp::__directive__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::__directive__ not supported in C++
+#endif
+#endif
+
+#if __has_attribute(__omp__::sequence)
+#ifndef __cplusplus
+#error __omp__::sequence supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::sequence not supported in C++
+#endif
+#endif
+
+#if __has_attribute(omp::__unknown__)
+#error omp::__unknown__ supported
+#endif
+
+#if __has_cpp_attribute(__omp__::directive)
+#ifndef __cplusplus
+#error __omp__::directive supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::directive not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(omp::__sequence__)
+#ifndef __cplusplus
+#error omp::__sequence__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::__sequence__ not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(__omp__::unknown)
+#error __omp__::unknown supported
+#endif
diff --git a/gcc/testsuite/c-c++-common/gomp/attrs-2.c b/gcc/testsuite/c-c++-common/gomp/attrs-2.c
new file mode 100644
index 0000000..21abcdd
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/attrs-2.c
@@ -0,0 +1,146 @@
+/* { dg-do compile } */
+/* { dg-options "-fno-openmp -fopenmp-simd" } */
+
+#if __has_attribute(omp::directive)
+#ifndef __cplusplus
+#error omp::directive supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::directive not supported in C++
+#endif
+#endif
+
+#if __has_attribute(omp::sequence)
+#ifndef __cplusplus
+#error omp::sequence supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::sequence not supported in C++
+#endif
+#endif
+
+#if __has_attribute(omp::unknown)
+#error omp::unknown supported
+#endif
+
+#if __has_cpp_attribute(omp::directive)
+#ifndef __cplusplus
+#error omp::directive supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::directive not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(omp::sequence)
+#ifndef __cplusplus
+#error omp::sequence supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::sequence not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(omp::unknown)
+#error omp::unknown supported
+#endif
+
+#if __has_attribute(__omp__::__directive__)
+#ifndef __cplusplus
+#error __omp__::__directive__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__directive__ not supported in C++
+#endif
+#endif
+
+#if __has_attribute(__omp__::__sequence__)
+#ifndef __cplusplus
+#error __omp__::__sequence__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__sequence__ not supported in C++
+#endif
+#endif
+
+#if __has_attribute(__omp__::__unknown__)
+#error __omp__::__unknown__ supported
+#endif
+
+#if __has_cpp_attribute(__omp__::__directive__)
+#ifndef __cplusplus
+#error __omp__::__directive__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__directive__ not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(__omp__::__sequence__)
+#ifndef __cplusplus
+#error __omp__::__sequence__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::__sequence__ not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(__omp__::__unknown__)
+#error __omp__::__unknown__ supported
+#endif
+
+#if __has_attribute(omp::__directive__)
+#ifndef __cplusplus
+#error omp::__directive__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::__directive__ not supported in C++
+#endif
+#endif
+
+#if __has_attribute(__omp__::sequence)
+#ifndef __cplusplus
+#error __omp__::sequence supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::sequence not supported in C++
+#endif
+#endif
+
+#if __has_attribute(omp::__unknown__)
+#error omp::__unknown__ supported
+#endif
+
+#if __has_cpp_attribute(__omp__::directive)
+#ifndef __cplusplus
+#error __omp__::directive supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error __omp__::directive not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(omp::__sequence__)
+#ifndef __cplusplus
+#error omp::__sequence__ supported in C
+#endif
+#else
+#ifdef __cplusplus
+#error omp::__sequence__ not supported in C++
+#endif
+#endif
+
+#if __has_cpp_attribute(__omp__::unknown)
+#error __omp__::unknown supported
+#endif
diff --git a/gcc/testsuite/c-c++-common/gomp/attrs-3.c b/gcc/testsuite/c-c++-common/gomp/attrs-3.c
new file mode 100644
index 0000000..5900244
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/attrs-3.c
@@ -0,0 +1,74 @@
+/* { dg-do compile } */
+/* { dg-options "-fno-openmp -fno-openmp-simd" } */
+
+#if __has_attribute(omp::directive)
+#error omp::directive supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_attribute(omp::sequence)
+#error omp::sequence supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_attribute(omp::unknown)
+#error omp::unknown supported
+#endif
+
+#if __has_cpp_attribute(omp::directive)
+#error omp::directive supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_cpp_attribute(omp::sequence)
+#error omp::sequence supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_cpp_attribute(omp::unknown)
+#error omp::unknown supported
+#endif
+
+#if __has_attribute(__omp__::__directive__)
+#error __omp__::__directive__ supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_attribute(__omp__::__sequence__)
+#error __omp__::__sequence__ supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_attribute(__omp__::__unknown__)
+#error __omp__::__unknown__ supported
+#endif
+
+#if __has_cpp_attribute(__omp__::__directive__)
+#error __omp__::__directive__ supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_cpp_attribute(__omp__::__sequence__)
+#error __omp__::__sequence__ supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_cpp_attribute(__omp__::__unknown__)
+#error __omp__::__unknown__ supported
+#endif
+
+#if __has_attribute(omp::__directive__)
+#error omp::__directive__ supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_attribute(__omp__::sequence)
+#error __omp__::sequence supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_attribute(omp::__unknown__)
+#error omp::__unknown__ supported
+#endif
+
+#if __has_cpp_attribute(__omp__::directive)
+#error __omp__::directive supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_cpp_attribute(omp::__sequence__)
+#error omp::__sequence__ supported even when -fno-openmp{,-simd}
+#endif
+
+#if __has_cpp_attribute(__omp__::unknown)
+#error __omp__::unknown supported
+#endif