[Patch] OpenMP: Document ompx warnings + add Fortran omx warning [PR106670]

2022-08-29 Thread Tobias Burnus

(Patch + RFC.)

OpenMP 5.2 has 'ompx' and (for fixed source form Fortran) 'omx'
as sentinel to provide a defined namespace for vendor extensions.

The behavior when encountering an unknown directive with ompx/omp sentinel
(or an unknown clause with ompx_ prefix) is implementation defined. For unknown
clauses there will be always an error in GCC.
For sentinels, GCC compiles the code and ignores the directive.

From the user perspective, either silently ignoring the directive or

showing a warning or showing an erroring is best - depending on the semantic
of that vendor extension. As the semantic is not known, providing a means
to warn makes most sense.

For warning, we can either show a
- specific message for ompx/omx - or a
- generic message
And we can either use some existing generic flag (unknown pragmas,
attributes, suprising behavior etc.), depending on language and source
language (C, C++, Fortran fixed/free)- or add & use a specific -W flag.

The attached patch just documents the existing warning behavior, which
is quite diverse + adds testcases for them. As fixed-form Fortran had no
warning, a new warning with a specific message was added.
(Cf. testcases in the patch for what's shown as message.)

OK for mainline - or other ideas how to handle this topic best?

Tobias


-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
München, HRB 106955
OpenMP: Document ompx warnings + add Fortran omx warning [PR106670]

omp/ompx sentinels are for vendor extensions; as they might be required for
the correctness of the program, a warning should be printable. This patch
documents in the OpenMP 5.2 table the existing warnings, including the new
warning for for fixed source form Fortran.

	PR fortran/106670

gcc/fortran/ChangeLog:

	* scanner.cc (skip_fixed_omp_sentinel): Add -Wsurprising warning
	for 'omx' sentinels with -fopenmp.
	* invoke.texi (-Wsurprising): Document additional warning case.

libgomp/ChangeLog:

	* libgomp.texi (OpenMP 5.2): Add comment to ompx/omx entry.

gcc/testsuite/ChangeLog:

	* c-c++-common/gomp/ompx-1.c: New test.
	* c-c++-common/gomp/ompx-2.c: New test.
	* g++.dg/gomp/ompx-attrs-1.C: New test.
	* gfortran.dg/gomp/ompx-1.f90: New test.
	* gfortran.dg/gomp/omx-1.f: New test.
	* gfortran.dg/gomp/omx-2.f: New test.

 gcc/fortran/invoke.texi   | 5 +
 gcc/fortran/scanner.cc| 8 ++--
 gcc/testsuite/c-c++-common/gomp/ompx-1.c  | 4 
 gcc/testsuite/c-c++-common/gomp/ompx-2.c  | 5 +
 gcc/testsuite/g++.dg/gomp/ompx-attrs-1.C  | 7 +++
 gcc/testsuite/gfortran.dg/gomp/ompx-1.f90 | 2 ++
 gcc/testsuite/gfortran.dg/gomp/omx-1.f| 7 +++
 gcc/testsuite/gfortran.dg/gomp/omx-2.f| 9 +
 libgomp/libgomp.texi  | 8 +++-
 9 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 4d1e0d6b513..58502d38ac8 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -1092,6 +1092,11 @@ The type of a function result is declared more than once with the same type.  If
 
 @item
 A @code{CHARACTER} variable is declared with negative length.
+
+@item
+With @option{-fopenmp}, for fixed-form source code, when an @code{omx}
+vendor-extension sentinel is encountered. (The equivalent @code{ompx},
+used in free-form source code, is diagnosed by default.)
 @end itemize
 
 @item -Wtabs
diff --git a/gcc/fortran/scanner.cc b/gcc/fortran/scanner.cc
index 2dff2514700..fa1d9cba394 100644
--- a/gcc/fortran/scanner.cc
+++ b/gcc/fortran/scanner.cc
@@ -982,8 +982,9 @@ static bool
 skip_fixed_omp_sentinel (locus *start)
 {
   gfc_char_t c;
-  if (((c = next_char ()) == 'm' || c == 'M')
-  && ((c = next_char ()) == 'p' || c == 'P'))
+  if ((c = next_char ()) != 'm' && c != 'M')
+return false;
+  if ((c = next_char ()) == 'p' || c == 'P')
 {
   c = next_char ();
   if (c != '\n'
@@ -1005,6 +1006,9 @@ skip_fixed_omp_sentinel (locus *start)
 	}
 	}
 }
+  else if (UNLIKELY (c == 'x' || c == 'X'))
+gfc_warning_now (OPT_Wsurprising,
+		 "Ignoring '!$omx' vendor-extension sentinel at %C");
   return false;
 }
 
diff --git a/gcc/testsuite/c-c++-common/gomp/ompx-1.c b/gcc/testsuite/c-c++-common/gomp/ompx-1.c
new file mode 100644
index 000..9758d0f0cae
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/ompx-1.c
@@ -0,0 +1,4 @@
+void f(void)
+{
+  #pragma ompx some_vendor_extension
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/ompx-2.c b/gcc/testsuite/c-c++-common/gomp/ompx-2.c
new file mode 100644
index 000..4b66b0e2b1c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/ompx-2.c
@@ -0,0 +1,5 @@
+/* { dg-additional-options "-Wunknown-pragmas" } */
+void f(void)
+{
+  #pragma ompx some_vendor_extension  /* { dg-warning "-:ignoring '#pragma ompx

Re: [Patch] OpenMP/Fortran: Permit end-clause on directive

2022-08-29 Thread Harald Anlauf via Fortran

Hi Tobias,

this is not really a review, but:

Am 26.08.22 um 20:21 schrieb Tobias Burnus:

I did run into some issues related to this; those turned out to be
unrelated, but I end ended up implementing this feature.

Side remark: 'omp parallel workshare' seems to actually permit 'nowait'
now, but I guess that's an unintended change due to the
syntax-representation change. Hence, it is now tracked as Spec Issue
3338 and I do not permit it.

OK for mainline?


Regarding testcase nowait-4.f90: it has a part that tests for many
formally correct uses, and a part that tests for many invalid nowait.
Both parts seem to be giving reasonable coverage, so I wonder whether
it would be beneficial to split this one into two subsets.

It makes sense to have fewer but larger testcases in the testsuite,
to keep the time for regtesting at bay, but I'm split here on this
one - and yes, pun intended.

Harald


Tobias
-
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201,
80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer:
Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München;
Registergericht München, HRB 106955