]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Handle OpenMP directives in attribute syntax in attribute-declaration
authorJakub Jelinek <jakub@redhat.com>
Sun, 1 Aug 2021 12:31:01 +0000 (14:31 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Sun, 1 Aug 2021 12:31:12 +0000 (14:31 +0200)
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.

(cherry picked from commit 05bcef5a88b34dd13179cabbe902e9135cb40ffe)

gcc/cp/ChangeLog.omp
gcc/cp/parser.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/g++.dg/gomp/attrs-9.C [new file with mode: 0644]

index c7c267aae693324fadf3c166cbf66af4363395ab..278c9aa67fd22f161f40dca6c663e0fdac1cf0db 100644 (file)
@@ -1,3 +1,11 @@
+2021-08-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-07-31  Jakub Jelinek  <jakub@redhat.com>
+
+       * parser.c (cp_parser_declaration): Handle OpenMP directives
+       in attribute-declaration.
+
 2021-07-30  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master:
index 0e62c5b69fdd3ef75a2bc7c145506cb7be38bff7..4c73128a11b73e1b54d506ef89c1ba0b68a2663b 100644 (file)
@@ -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");
index 6437bc32db8e43e0ea957ebca70888e224d85c2d..300a9a75f9a1b7a671ffa83271e93affcf6ab975 100644 (file)
@@ -1,3 +1,10 @@
+2021-08-01  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-07-31  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.dg/gomp/attrs-9.C: New test.
+
 2021-07-30  Tobias Burnus  <tobias@codesourcery.com>
 
        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 (file)
index 0000000..0af556c
--- /dev/null
@@ -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)]];