public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2650] openmp: Handle OpenMP directives in attribute syntax in attribute-declaration
@ 2021-07-31  7:39 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-07-31  7:39 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:05bcef5a88b34dd13179cabbe902e9135cb40ffe

commit r12-2650-g05bcef5a88b34dd13179cabbe902e9135cb40ffe
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Jul 31 09:35:25 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  <jakub@redhat.com>
    
            * parser.c (cp_parser_declaration): Handle OpenMP directives
            in attribute-declaration.
    
            * g++.dg/gomp/attrs-9.C: New test.

Diff:
---
 gcc/cp/parser.c                     | 19 +++++++++++++++++++
 gcc/testsuite/g++.dg/gomp/attrs-9.C | 15 +++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ab74e9d2fb7..47bf7d9ad1f 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -14431,6 +14431,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/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)]];


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-31  7:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  7:39 [gcc r12-2650] openmp: Handle OpenMP directives in attribute syntax in attribute-declaration Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).