openmp: Adjust handling of __has_attribute (omp::directive)/sequence and add omp::decl

I forgot to tweak c_common_has_attribute for the C++ omp::decl addition and now
also for the C omp::{directive,sequence,decl} addition.

2023-11-05  Jakub Jelinek  <jakub@redhat.com>

	* c-lex.cc (c_common_has_attribute): Return 1 for omp::directive
	and omp::sequence with -fopenmp or -fopenmp-simd also for C, not
	just for C++.  Return 1 for omp::decl with -fopenmp or -fopenmp-simd
	for both C and C++.

	* c-c++-common/gomp/attrs-1.c: Adjust for omp::directive and
	omp::sequence being supported also in C and add tests for omp::decl.
	* c-c++-common/gomp/attrs-2.c: Likewise.
	* c-c++-common/gomp/attrs-3.c: Add tests for omp::decl.
This commit is contained in:
Jakub Jelinek 2023-11-05 18:28:37 +01:00
parent 0e6f3e9175
commit 26cf069416
4 changed files with 115 additions and 189 deletions

View file

@ -367,15 +367,13 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
= get_identifier ((const char *)
cpp_token_as_text (pfile, nxt_token));
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;
}
/* 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)
|| is_attribute_p ("decl", attr_id)))
result = 1;
if (result)
attr_name = NULL_TREE;
else

View file

@ -1,144 +1,96 @@
/* { 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
#if !__has_attribute(omp::directive)
#error omp::directive not supported in C/C++
#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++
#if !__has_attribute(omp::sequence)
#error omp::sequence not supported in C/C++
#endif
#if !__has_attribute(omp::decl)
#error omp::decl not supported in C/C++
#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
#if !__has_cpp_attribute(omp::directive)
#error omp::directive not supported in C/C++
#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++
#if !__has_cpp_attribute(omp::sequence)
#error omp::sequence not supported in C/C++
#endif
#if !__has_cpp_attribute(omp::decl)
#error omp::sequence not supported in C/C++
#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
#if !__has_attribute(__omp__::__directive__)
#error __omp__::__directive__ not supported in C/C++
#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++
#if !__has_attribute(__omp__::__sequence__)
#error __omp__::__sequence__ not supported in C/C++
#endif
#if !__has_attribute(__omp__::__decl__)
#error __omp__::__decl__ not supported in C/C++
#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
#if !__has_cpp_attribute(__omp__::__directive__)
#error __omp__::__directive__ not supported in C/C++
#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++
#if !__has_cpp_attribute(__omp__::__sequence__)
#error __omp__::__sequence__ not supported in C/C++
#endif
#if !__has_cpp_attribute(__omp__::__decl__)
#error __omp__::__decl__ not supported in C/C++
#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
#if !__has_attribute(omp::__directive__)
#error omp::__directive__ not supported in C/C++
#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++
#if !__has_attribute(__omp__::sequence)
#error __omp__::sequence not supported in C/C++
#endif
#if !__has_attribute(omp::__decl__)
#error omp::__decl__ not supported in C/C++
#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
#if !__has_cpp_attribute(__omp__::directive)
#error __omp__::directive not supported in C/C++
#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++
#if !__has_cpp_attribute(omp::__sequence__)
#error omp::__sequence__ not supported in C/C++
#endif
#if !__has_cpp_attribute(__omp__::decl)
#error __omp__::decl not supported in C/C++
#endif
#if __has_cpp_attribute(__omp__::unknown)

View file

@ -1,144 +1,96 @@
/* { 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
#if !__has_attribute(omp::directive)
#error omp::directive not supported in C/C++
#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++
#if !__has_attribute(omp::sequence)
#error omp::sequence not supported in C/C++
#endif
#if !__has_attribute(omp::decl)
#error omp::decl not supported in C/C++
#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
#if !__has_cpp_attribute(omp::directive)
#error omp::directive not supported in C/C++
#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++
#if !__has_cpp_attribute(omp::sequence)
#error omp::sequence not supported in C/C++
#endif
#if !__has_cpp_attribute(omp::decl)
#error omp::sequence not supported in C/C++
#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
#if !__has_attribute(__omp__::__directive__)
#error __omp__::__directive__ not supported in C/C++
#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++
#if !__has_attribute(__omp__::__sequence__)
#error __omp__::__sequence__ not supported in C/C++
#endif
#if !__has_attribute(__omp__::__decl__)
#error __omp__::__decl__ not supported in C/C++
#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
#if !__has_cpp_attribute(__omp__::__directive__)
#error __omp__::__directive__ not supported in C/C++
#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++
#if !__has_cpp_attribute(__omp__::__sequence__)
#error __omp__::__sequence__ not supported in C/C++
#endif
#if !__has_cpp_attribute(__omp__::__decl__)
#error __omp__::__decl__ not supported in C/C++
#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
#if !__has_attribute(omp::__directive__)
#error omp::__directive__ not supported in C/C++
#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++
#if !__has_attribute(__omp__::sequence)
#error __omp__::sequence not supported in C/C++
#endif
#if !__has_attribute(omp::__decl__)
#error omp::__decl__ not supported in C/C++
#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
#if !__has_cpp_attribute(__omp__::directive)
#error __omp__::directive not supported in C/C++
#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++
#if !__has_cpp_attribute(omp::__sequence__)
#error omp::__sequence__ not supported in C/C++
#endif
#if !__has_cpp_attribute(__omp__::decl)
#error __omp__::decl not supported in C/C++
#endif
#if __has_cpp_attribute(__omp__::unknown)

View file

@ -9,6 +9,10 @@
#error omp::sequence supported even when -fno-openmp{,-simd}
#endif
#if __has_attribute(omp::decl)
#error omp::decl supported even when -fno-openmp{,-simd}
#endif
#if __has_attribute(omp::unknown)
#error omp::unknown supported
#endif
@ -21,6 +25,10 @@
#error omp::sequence supported even when -fno-openmp{,-simd}
#endif
#if __has_cpp_attribute(omp::decl)
#error omp::decl supported even when -fno-openmp{,-simd}
#endif
#if __has_cpp_attribute(omp::unknown)
#error omp::unknown supported
#endif
@ -33,6 +41,10 @@
#error __omp__::__sequence__ supported even when -fno-openmp{,-simd}
#endif
#if __has_attribute(__omp__::__decl__)
#error __omp__::__decl__ supported even when -fno-openmp{,-simd}
#endif
#if __has_attribute(__omp__::__unknown__)
#error __omp__::__unknown__ supported
#endif
@ -45,6 +57,10 @@
#error __omp__::__sequence__ supported even when -fno-openmp{,-simd}
#endif
#if __has_cpp_attribute(__omp__::__decl__)
#error __omp__::__decl__ supported even when -fno-openmp{,-simd}
#endif
#if __has_cpp_attribute(__omp__::__unknown__)
#error __omp__::__unknown__ supported
#endif
@ -57,6 +73,10 @@
#error __omp__::sequence supported even when -fno-openmp{,-simd}
#endif
#if __has_attribute(omp::__decl__)
#error omp::__decl__ supported even when -fno-openmp{,-simd}
#endif
#if __has_attribute(omp::__unknown__)
#error omp::__unknown__ supported
#endif
@ -69,6 +89,10 @@
#error omp::__sequence__ supported even when -fno-openmp{,-simd}
#endif
#if __has_cpp_attribute(__omp__::decl)
#error __omp__::decl supported even when -fno-openmp{,-simd}
#endif
#if __has_cpp_attribute(__omp__::unknown)
#error __omp__::unknown supported
#endif