https://gcc.gnu.org/g:7f8bb6498691cace5cced224bfc72d13724c9b82

commit r15-6966-g7f8bb6498691cace5cced224bfc72d13724c9b82
Author: Sandra Loosemore <sloosem...@baylibre.com>
Date:   Wed Jan 15 17:22:53 2025 +0000

    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.

Diff:
---
 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 +++++-----
 gcc/testsuite/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 b45c7ef961f4..f193329099f5 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 74f4f7cd6d89..ba2c4dbb0538 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 0f1aaa021812..e51ff1f4d29e 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -1620,7 +1620,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 47396055aef1..95a65fd06cee 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 924f323d68f7..68b88bed9e43 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 15dae6419338..66b918078083 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 73e5bbcf71b0..063431d3582a 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 c8719a86a948..5694811b4289 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

Reply via email to