Hi Tobias,

On 07/01/2025 12:13, Tobias Burnus wrote:
Paul-Antoine Arras wrote:
This is a followup to
ed49709acda OpenMP: C++ front-end support for dispatch + adjust_args.

The call to cp_parser_omp_dispatch only belongs in cp_parser_omp_construct. In cp_parser_pragma, handle PRAGMA_OMP_DISPATCH by calling cp_parser_omp_construct.

I think this change is good - but not sufficient. For instance,
the following gives an ICE:

void k();
struct t {
  #pragma omp dispatch
   k();
};

I think that's context == pragma_member.


This amended patch checks the context and adds the suggested testcase.

Thanks,
--
PA
commit 7f91528dc54d260a489c749a8c5ccc004a96bfac
Author: Paul-Antoine Arras <par...@baylibre.com>
Date:   Mon Jan 6 16:06:43 2025 +0100

    Do not call cp_parser_omp_dispatch directly in cp_parser_pragma
    
    This is a followup to
    ed49709acda OpenMP: C++ front-end support for dispatch + adjust_args.
    
    The call to cp_parser_omp_dispatch only belongs in cp_parser_omp_construct. In
    cp_parser_pragma, handle PRAGMA_OMP_DISPATCH by calling cp_parser_omp_construct.
    
    gcc/cp/ChangeLog:
    
            * parser.cc (cp_parser_pragma): Replace call to cp_parser_omp_dispatch
            with cp_parser_omp_construct.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/gomp/dispatch-8.C: New test.

diff --git gcc/cp/parser.cc gcc/cp/parser.cc
index f548dc31c2b..e28c23141c0 100644
--- gcc/cp/parser.cc
+++ gcc/cp/parser.cc
@@ -53060,7 +53060,9 @@ cp_parser_pragma (cp_parser *parser, enum pragma_context context, bool *if_p)
       break;
 
     case PRAGMA_OMP_DISPATCH:
-      cp_parser_omp_dispatch (parser, pragma_tok);
+      if (context != pragma_stmt && context != pragma_compound)
+	goto bad_stmt;
+      cp_parser_omp_construct (parser, pragma_tok, if_p);
       return true;
 
     case PRAGMA_IVDEP:
diff --git gcc/testsuite/g++.dg/gomp/dispatch-8.C gcc/testsuite/g++.dg/gomp/dispatch-8.C
new file mode 100644
index 00000000000..b8e8e73db1f
--- /dev/null
+++ gcc/testsuite/g++.dg/gomp/dispatch-8.C
@@ -0,0 +1,10 @@
+// { dg-do compile }
+
+// Check that an appropriate diagnostic is emitted when a dispatch directive
+// appears in a pragma_member context.
+
+void k();
+struct t {
+ #pragma omp dispatch  // { dg-error "expected declaration specifiers before end of line" }
+  k();  // { dg-error ".*" }
+};

Reply via email to