On 1/14/25 20:38, Sandra Loosemore wrote:
I've incorporated a fix for Tobias's recent comment about recognizing
C_OMP_DIR_META in the "assumes" directive in the C and C++ front ends, but
I've deferred fixing the wording of the existing error message because it
affects a pile of testcases unrelated to metadirectives, and also because
I want to tweak the Fortran message too.  I think I can address this later
using my documentation maintainer superpowers.  ;-)

I've now pushed the attached cleanup for that issue, along with parts 1, 2, 3, and 5 of this series. Part 4 (the Fortran front end changes) is still pending review, and part 6 depends on part 4.

Besides diagnostic message wording being within my realm as documentation maintainer, Tobias approved the attached patch offline as well.

-Sandra
From e3514e01c60def48dfbba51805ec8cce0e1949e8 Mon Sep 17 00:00:00 2001
From: Sandra Loosemore <sloosem...@baylibre.com>
Date: Wed, 15 Jan 2025 17:22:53 +0000
Subject: [PATCH] OpenMP: Improve error message for invalid directive in
 "assumes".

gcc/c/ChangeLog
	* c-parser.cc (c_parser_omp_assumption_clauses): Give a more specific
	error message for invalid directives vs unknown names.

gcc/cp/ChangeLog
	* parser.cc (cp_parser_omp_assumption_clauses): Give a more specific
	error message for invalid directives vs unknown names.

gcc/fortran/ChangeLog
	* openmp.cc (gfc_omp_absent_contains_clause): Use an Oxford comma
	in the message.

gcc/testsuite/ChangeLog
	* c-c++-common/gomp/assume-2.c: Adjust expected diagnostics.
	* c-c++-common/gomp/assumes-2.c: Likewise.
	* c-c++-common/gomp/begin-assumes-2.c: Likewise.
	* gfortran.dg/gomp/allocate-6.f90: Likewise.
	* gfortran.dg/gomp/assumes-2.f90: Likewise.
---
 gcc/c/c-parser.cc                             | 19 ++++++++++++-------
 gcc/cp/parser.cc                              | 13 +++++++++----
 gcc/fortran/openmp.cc                         |  2 +-
 gcc/testsuite/c-c++-common/gomp/assume-2.c    | 10 +++++-----
 gcc/testsuite/c-c++-common/gomp/assumes-2.c   | 10 +++++-----
 .../c-c++-common/gomp/begin-assumes-2.c       | 10 +++++-----
 gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 |  4 ++--
 gcc/testsuite/gfortran.dg/gomp/assumes-2.f90  |  2 +-
 8 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index b45c7ef961f..f193329099f 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -28846,13 +28846,18 @@ c_parser_omp_assumption_clauses (c_parser *parser, bool is_assume)
 			= c_omp_categorize_directive (directive[0],
 						      directive[1],
 						      directive[2]);
-		      if (dir == NULL
-			  || dir->kind == C_OMP_DIR_DECLARATIVE
-			  || dir->kind == C_OMP_DIR_INFORMATIONAL
-			  || dir->kind == C_OMP_DIR_META
-			  || dir->id == PRAGMA_OMP_END
-			  || (!dir->second && directive[1])
-			  || (!dir->third && directive[2]))
+		      if (dir
+			  && (dir->kind == C_OMP_DIR_DECLARATIVE
+			      || dir->kind == C_OMP_DIR_INFORMATIONAL
+			      || dir->kind == C_OMP_DIR_META))
+			error_at (dloc, "invalid OpenMP directive name in "
+					"%qs clause argument: declarative, "
+					"informational, and meta directives "
+					"not permitted", p);
+		      else if (dir == NULL
+			       || dir->id == PRAGMA_OMP_END
+			       || (!dir->second && directive[1])
+			       || (!dir->third && directive[2]))
 			error_at (dloc, "unknown OpenMP directive name in "
 					"%qs clause argument", p);
 		      else
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 82fac649d0c..775680a067d 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -49887,10 +49887,15 @@ cp_parser_omp_assumption_clauses (cp_parser *parser, cp_token *pragma_tok,
 			= c_omp_categorize_directive (directive[0],
 						      directive[1],
 						      directive[2]);
-		      if (dir == NULL
-			  || dir->kind == C_OMP_DIR_DECLARATIVE
-			  || dir->kind == C_OMP_DIR_INFORMATIONAL
-			  || dir->kind == C_OMP_DIR_META
+		      if (dir
+			  && (dir->kind == C_OMP_DIR_DECLARATIVE
+			      || dir->kind == C_OMP_DIR_INFORMATIONAL
+			      || dir->kind == C_OMP_DIR_META))
+			error_at (dloc, "invalid OpenMP directive name in "
+					"%qs clause argument: declarative, "
+					"informational, and meta directives "
+					"not permitted", p);
+		      else if (dir == NULL
 			  || dir->id == PRAGMA_OMP_END
 			  || (!dir->second && directive[1])
 			  || (!dir->third && directive[2]))
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index c2adefd58d6..b49745a9fe0 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -1642,7 +1642,7 @@ gfc_omp_absent_contains_clause (gfc_omp_assumptions **assume, bool is_absent)
 	  || kind == GFC_OMP_DIR_META)
 	{
 	  gfc_error ("Invalid %qs directive at %L in %s clause: declarative, "
-		     "informational and meta directives not permitted",
+		     "informational, and meta directives not permitted",
 		     gfc_ascii_statement (st, true), &old_loc,
 		     is_absent ? "ABSENT" : "CONTAINS");
 	  return MATCH_ERROR;
diff --git a/gcc/testsuite/c-c++-common/gomp/assume-2.c b/gcc/testsuite/c-c++-common/gomp/assume-2.c
index 47396055aef..95a65fd06ce 100644
--- a/gcc/testsuite/c-c++-common/gomp/assume-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/assume-2.c
@@ -19,19 +19,19 @@ foo (int i, int *a)
   ;
   #pragma omp assume contains (target enter data, target exit data) absent (target enter data, parallel)	/* { dg-error "'target enter data' directive mentioned in both 'absent' and 'contains' clauses" } */
   ;
-  #pragma omp assume contains (declare target)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+  #pragma omp assume contains (declare target)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
   ;
   #pragma omp assume absent (parallel for simd)			/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
   ;
   #pragma omp assume contains (target parallel)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
   ;
-  #pragma omp assume absent (assume)				/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
+  #pragma omp assume absent (assume)				/* { dg-error "invalid OpenMP directive name in 'absent' clause argument" } */
   ;
-  #pragma omp assume absent (assumes)				/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
+  #pragma omp assume absent (assumes)				/* { dg-error "invalid OpenMP directive name in 'absent' clause argument" } */
   ;
-  #pragma omp assume contains (begin assumes)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+  #pragma omp assume contains (begin assumes)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
   ;
-  #pragma omp assume contains (end assumes)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+  #pragma omp assume contains (end assumes)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
   ;
   #pragma omp assume contains (foo)				/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
   ;
diff --git a/gcc/testsuite/c-c++-common/gomp/assumes-2.c b/gcc/testsuite/c-c++-common/gomp/assumes-2.c
index 924f323d68f..68b88bed9e4 100644
--- a/gcc/testsuite/c-c++-common/gomp/assumes-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/assumes-2.c
@@ -7,13 +7,13 @@
 #pragma omp assumes contains (target enter data, target exit data) contains (target exit data, parallel)	/* { dg-error "target exit data' directive mentioned multiple times in 'contains' clauses" } */
 #pragma omp assumes absent (target enter data, target exit data) contains (target exit data, parallel)		/* { dg-error "'target exit data' directive mentioned in both 'absent' and 'contains' clauses" } */
 #pragma omp assumes contains (target enter data, target exit data) absent (target enter data, parallel)	/* { dg-error "'target enter data' directive mentioned in both 'absent' and 'contains' clauses" } */
-#pragma omp assumes contains (declare target)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+#pragma omp assumes contains (declare target)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
 #pragma omp assumes absent (parallel for simd)			/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
 #pragma omp assumes contains (target parallel)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
-#pragma omp assumes absent (assume)				/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
-#pragma omp assumes absent (assumes)				/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
-#pragma omp assumes contains (begin assumes)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
-#pragma omp assumes contains (end assumes)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+#pragma omp assumes absent (assume)				/* { dg-error "invalid OpenMP directive name in 'absent' clause argument" } */
+#pragma omp assumes absent (assumes)				/* { dg-error "invalid OpenMP directive name in 'absent' clause argument" } */
+#pragma omp assumes contains (begin assumes)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
+#pragma omp assumes contains (end assumes)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
 #pragma omp assumes contains (foo)				/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
 #pragma omp assumes absent (target enter something)		/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
 #pragma omp assumes foobar					/* { dg-error "expected assumption clause" } */
diff --git a/gcc/testsuite/c-c++-common/gomp/begin-assumes-2.c b/gcc/testsuite/c-c++-common/gomp/begin-assumes-2.c
index 15dae641933..66b91807808 100644
--- a/gcc/testsuite/c-c++-common/gomp/begin-assumes-2.c
+++ b/gcc/testsuite/c-c++-common/gomp/begin-assumes-2.c
@@ -25,7 +25,7 @@ void f8 (void) {}
 #pragma omp begin assumes contains (target enter data, target exit data) absent (target enter data, parallel)	/* { dg-error "'target enter data' directive mentioned in both 'absent' and 'contains' clauses" } */
 void f9 (void) {}
 #pragma omp end assumes
-#pragma omp begin assumes contains (declare target)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+#pragma omp begin assumes contains (declare target)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
 void f10 (void) {}
 #pragma omp end assumes
 #pragma omp begin assumes absent (parallel for simd)			/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
@@ -34,16 +34,16 @@ void f11 (void) {}
 #pragma omp begin assumes contains (target parallel)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
 void f12 (void) {}
 #pragma omp end assumes
-#pragma omp begin assumes absent (assume)				/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
+#pragma omp begin assumes absent (assume)				/* { dg-error "invalid OpenMP directive name in 'absent' clause argument" } */
 void f13 (void) {}
 #pragma omp end assumes
-#pragma omp begin assumes absent (assumes)				/* { dg-error "unknown OpenMP directive name in 'absent' clause argument" } */
+#pragma omp begin assumes absent (assumes)				/* { dg-error "invalid OpenMP directive name in 'absent' clause argument" } */
 void f14 (void) {}
 #pragma omp end assumes
-#pragma omp begin assumes contains (begin assumes)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+#pragma omp begin assumes contains (begin assumes)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
 void f15 (void) {}
 #pragma omp end assumes
-#pragma omp begin assumes contains (end assumes)			/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
+#pragma omp begin assumes contains (end assumes)			/* { dg-error "invalid OpenMP directive name in 'contains' clause argument" } */
 void f16 (void) {}
 #pragma omp end assumes
 #pragma omp begin assumes contains (foo)				/* { dg-error "unknown OpenMP directive name in 'contains' clause argument" } */
diff --git a/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90 b/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90
index 73e5bbcf71b..063431d3582 100644
--- a/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/allocate-6.f90
@@ -30,9 +30,9 @@ module my_omp_lib
 end module my_omp_lib
 
 subroutine zero()
-  !$omp assumes absent (allocate)  ! { dg-error "Invalid 'ALLOCATE' directive at .1. in ABSENT clause: declarative, informational and meta directives not permitted" }
+  !$omp assumes absent (allocate)  ! { dg-error "Invalid 'ALLOCATE' directive at .1. in ABSENT clause: declarative, informational, and meta directives not permitted" }
 
-  !$omp assume absent (allocate)  ! { dg-error "Invalid 'ALLOCATE' directive at .1. in ABSENT clause: declarative, informational and meta directives not permitted" }
+  !$omp assume absent (allocate)  ! { dg-error "Invalid 'ALLOCATE' directive at .1. in ABSENT clause: declarative, informational, and meta directives not permitted" }
   !!$omp end assume
 end
 
diff --git a/gcc/testsuite/gfortran.dg/gomp/assumes-2.f90 b/gcc/testsuite/gfortran.dg/gomp/assumes-2.f90
index c8719a86a94..5694811b428 100644
--- a/gcc/testsuite/gfortran.dg/gomp/assumes-2.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/assumes-2.f90
@@ -11,7 +11,7 @@ module m2
 interface
   subroutine foo
     !$omp assumes contains(target) contains(teams,target) ! { dg-error "'TARGET' directive mentioned multiple times in CONTAINS clause in !.OMP ASSUMES directive" }
-    !$omp assumes absent(declare target) ! { dg-error "Invalid 'DECLARE TARGET' directive at .1. in ABSENT clause: declarative, informational and meta directives not permitted" }
+    !$omp assumes absent(declare target) ! { dg-error "Invalid 'DECLARE TARGET' directive at .1. in ABSENT clause: declarative, informational, and meta directives not permitted" }
     !$omp assumes absent(parallel) absent(do,simd,parallel,distribute) ! { dg-error "'PARALLEL' directive mentioned multiple times in ABSENT clause in !.OMP ASSUMES directive" }
     !$omp assumes contains(barrier,atomic) absent(cancel,simd,atomic,distribute) ! { dg-error "'SIMD' directive mentioned both times in ABSENT and CONTAINS clauses in !.OMP ASSUMES directive" }
   end subroutine foo
-- 
2.34.1

Reply via email to