From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 095753858439; Sun, 1 Aug 2021 12:31:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 095753858439 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-11] openmp: Handle OpenMP directives in attribute syntax in attribute-declaration X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/devel/omp/gcc-11 X-Git-Oldrev: ae7c303d04e0bd4a933d43c01e404cef037c7f4d X-Git-Newrev: 69b1e8c24d1c84322fb385d40aa930313aca710e Message-Id: <20210801123126.095753858439@sourceware.org> Date: Sun, 1 Aug 2021 12:31:26 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Aug 2021 12:31:26 -0000 https://gcc.gnu.org/g:69b1e8c24d1c84322fb385d40aa930313aca710e commit 69b1e8c24d1c84322fb385d40aa930313aca710e Author: Jakub Jelinek Date: Sun Aug 1 14:31:01 2021 +0200 openmp: Handle OpenMP directives in attribute syntax in attribute-declaration Now that we parse attribute-declaration (outside of functions), the following patch handles OpenMP directives in its attribute(s). What needs handling incrementally is diagnose mismatching begin/end pair like [[omp::directive (declare target)]]; int a; #pragma omp end declare target or #pragma omp declare target int b; [[omp::directive (end declare target)]]; and handling declare simd/declare variant on declarations (function definitions and declarations), for those in two different spots. 2021-07-31 Jakub Jelinek * parser.c (cp_parser_declaration): Handle OpenMP directives in attribute-declaration. * g++.dg/gomp/attrs-9.C: New test. (cherry picked from commit 05bcef5a88b34dd13179cabbe902e9135cb40ffe) Diff: --- gcc/cp/ChangeLog.omp | 8 ++++++++ gcc/cp/parser.c | 19 +++++++++++++++++++ gcc/testsuite/ChangeLog.omp | 7 +++++++ gcc/testsuite/g++.dg/gomp/attrs-9.C | 15 +++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp index c7c267aae69..278c9aa67fd 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,11 @@ +2021-08-01 Tobias Burnus + + Backported from master: + 2021-07-31 Jakub Jelinek + + * parser.c (cp_parser_declaration): Handle OpenMP directives + in attribute-declaration. + 2021-07-30 Tobias Burnus Backported from master: diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0e62c5b69fd..4c73128a11b 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -14300,6 +14300,25 @@ cp_parser_declaration (cp_parser* parser, tree prefix_attrs) { location_t attrs_loc = token1->location; tree std_attrs = cp_parser_std_attribute_spec_seq (parser); + + if (std_attrs && (flag_openmp || flag_openmp_simd)) + { + gcc_assert (!parser->lexer->in_omp_attribute_pragma); + std_attrs = cp_parser_handle_statement_omp_attributes (parser, + std_attrs); + if (parser->lexer->in_omp_attribute_pragma) + { + cp_lexer *lexer = parser->lexer; + while (parser->lexer->in_omp_attribute_pragma) + { + gcc_assert (cp_lexer_next_token_is (parser->lexer, + CPP_PRAGMA)); + cp_parser_pragma (parser, pragma_external, NULL); + } + cp_lexer_destroy (lexer); + } + } + if (std_attrs != NULL_TREE) warning_at (make_location (attrs_loc, attrs_loc, parser->lexer), OPT_Wattributes, "attribute ignored"); diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 6437bc32db8..300a9a75f9a 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,10 @@ +2021-08-01 Tobias Burnus + + Backported from master: + 2021-07-31 Jakub Jelinek + + * g++.dg/gomp/attrs-9.C: New test. + 2021-07-30 Tobias Burnus Backported from master: diff --git a/gcc/testsuite/g++.dg/gomp/attrs-9.C b/gcc/testsuite/g++.dg/gomp/attrs-9.C new file mode 100644 index 00000000000..0af556c7284 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/attrs-9.C @@ -0,0 +1,15 @@ +// { dg-do compile { target c++11 } } + +[[omp::sequence (directive (requires, atomic_default_mem_order (seq_cst)))]]; +[[omp::directive (declare reduction (plus: int: omp_out += omp_in) initializer (omp_priv = 0))]]; +int a; +[[omp::directive (declare target (a))]]; +int t; +[[omp::sequence (omp::directive (threadprivate (t)))]]; +int b, c; +[[omp::directive (declare target, to (b), link (c))]]; +[[omp::directive (declare target)]]; +[[omp::directive (declare target)]]; +int d; +[[omp::directive (end declare target)]]; +[[omp::directive (end declare target)]];