While TR15 added 'message' and 'severity' to the 'target' and 'teams'
constructs, there were some inconsistencies regarding 'severity(warning)'
in that case. -> OpenMP Spec Issue #5010.
Thus, 'severity' was removed for those - and is only kept for 'parallel',
while 'message' still stays.

Accordingly, this patch removes it from the compiler (only implemented in
Fortran); the severity printing is related to 'message' - such that in line
with required error termination, there is still a 'severity(fatal)' printed
in the tree dump for target + teams, even if the clause is only permitted for
'parallel'. - Now with the white space fixed.

Committed asr17-5126-g4dc98e3ecd1b8e

Tobias
commit 4dc98e3ecd1b8ef06ccbff7108523f8a5be8ab30
Author: Tobias Burnus <[email protected]>
Date:   Tue Oct 13 17:44:30 2026 +0200

    OpenMP/Fortran: Disallow severity clause on target/teams
    
    Commit r17-2731-ga0694cfb5b488d added among others support for the message
    and severity clause on target and teams, stopping in the middle end with a
    "sorry, unimplemented" if an error action would be triggerable as the clause
    values are currently not passed to the library.
    
    Due to some inconsistencies regarding the error termination vs. printing a
    warning, the severity clause was removed for target and teams (but not for
    parallel) after OpenMP TR15 but before OpenMP 6.1 (Spec Issue 5010); for
    target/teams, those clauses were also only added in TR15.
    
    This commit reflects this by updating the parser, a comment in tree-core.h
    and adding a missing comma to the tree dump, which still shows
    'severity(fatal)' for target and teams. (The flag about warning is stored
    alongside the message clause; while the flag is not permitted, the message
    still implies a fatal error.)
    
    gcc/fortran/ChangeLog:
    
            * openmp.cc (OMP_TARGET_CLAUSES, OMP_TEAMS_CLAUSES): Remove
            OMP_CLAUSE_SEVERITY.
            * trans-openmp.cc (gfc_split_omp_clauses): Remove SEVERITY from
            clause splitting for target and teams.
    
    gcc/ChangeLog:
    
            * tree-core.h (enum omp_clause_code): Extend comment to
            OMP_CLAUSE_MESSAGE.
            * tree-pretty-print.cc (dump_omp_clause): Print space before
            'severity(fatal)'.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/gomp/spatial-dimensions-3.f90: Check that severity
            clause is not permitted with target/teams.
            * gfortran.dg/gomp/spatial-dimensions-4.f90: Remove severity clause
            on target/teams constructs except those with parallel; update
            expected tree dump.
            * gfortran.dg/gomp/spatial-dimensions-5.f90: Likewise.
---
 gcc/fortran/openmp.cc                              |  4 +--
 gcc/fortran/trans-openmp.cc                        |  4 ---
 .../gfortran.dg/gomp/spatial-dimensions-3.f90      | 15 +++++++++
 .../gfortran.dg/gomp/spatial-dimensions-4.f90      |  6 ++--
 .../gfortran.dg/gomp/spatial-dimensions-5.f90      | 38 +++++++++++-----------
 gcc/tree-core.h                                    |  4 ++-
 gcc/tree-pretty-print.cc                           |  3 +-
 7 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index ac2001e29b3..c1fe7e22e43 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -5912,7 +5912,7 @@ cleanup:
    | OMP_CLAUSE_THREAD_LIMIT | OMP_CLAUSE_ALLOCATE			\
    | OMP_CLAUSE_HAS_DEVICE_ADDR | OMP_CLAUSE_USES_ALLOCATORS		\
    | OMP_CLAUSE_DYN_GROUPPRIVATE | OMP_CLAUSE_DEVICE_TYPE		\
-   | OMP_CLAUSE_MESSAGE | OMP_CLAUSE_SEVERITY)
+   | OMP_CLAUSE_MESSAGE)
 #define OMP_TARGET_DATA_CLAUSES \
   (omp_mask (OMP_CLAUSE_DEVICE) | OMP_CLAUSE_MAP | OMP_CLAUSE_IF	\
    | OMP_CLAUSE_USE_DEVICE_PTR | OMP_CLAUSE_USE_DEVICE_ADDR)
@@ -5929,7 +5929,7 @@ cleanup:
   (omp_mask (OMP_CLAUSE_NUM_TEAMS) | OMP_CLAUSE_THREAD_LIMIT		\
    | OMP_CLAUSE_DEFAULT | OMP_CLAUSE_PRIVATE | OMP_CLAUSE_FIRSTPRIVATE	\
    | OMP_CLAUSE_SHARED | OMP_CLAUSE_REDUCTION | OMP_CLAUSE_ALLOCATE	\
-   | OMP_CLAUSE_MESSAGE | OMP_CLAUSE_SEVERITY)
+   | OMP_CLAUSE_MESSAGE)
 #define OMP_DISTRIBUTE_CLAUSES \
   (omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE		\
    | OMP_CLAUSE_LASTPRIVATE | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_DIST_SCHEDULE \
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index b6a9373ab51..bee9fd608ec 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -8589,8 +8589,6 @@ gfc_split_omp_clauses (gfc_code *code,
 	    = code->ext.omp_clauses->device_type;
 	  clausesa[GFC_OMP_SPLIT_TARGET].message
 	    = code->ext.omp_clauses->message;
-	  clausesa[GFC_OMP_SPLIT_TARGET].severity
-	    = code->ext.omp_clauses->severity;
 	}
       if (mask & GFC_OMP_MASK_TEAMS)
 	{
@@ -8614,8 +8612,6 @@ gfc_split_omp_clauses (gfc_code *code,
 	  /* Message is used on target, teams, and parallel.  */
 	  clausesa[GFC_OMP_SPLIT_TEAMS].message
 	    = code->ext.omp_clauses->message;
-	  clausesa[GFC_OMP_SPLIT_TEAMS].severity
-	    = code->ext.omp_clauses->severity;
 	}
       if (mask & GFC_OMP_MASK_DISTRIBUTE)
 	{
diff --git a/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-3.f90 b/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-3.f90
index 372924d55da..eb46f41354c 100644
--- a/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-3.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-3.f90
@@ -256,3 +256,18 @@ subroutine seven
   !$omp teams num_teams(strict : 4 : 5 )  ! { dg-error "Expected either '\\\[lower-expr : \\\] upper-expr' or 'dims\\(N\\): expr-list' at .1." }
   block; end block
 end
+
+! While teams and target take 'message', they do not take 'severity':
+subroutine eight
+  !$omp teams num_teams (2:2) severity(fatal)  ! { dg-error "31: Failed to match clause at .1." }
+  block; end block
+
+  !$omp teams num_teams (2) message("abc") severity(fatal)  ! { dg-error "44: Failed to match clause at .1." }
+  block; end block
+
+  !$omp target severity(fatal)  ! { dg-error "16: Failed to match clause at .1." }
+  block; end block
+
+  !$omp target teams message("abc") severity(fatal)  ! { dg-error "37: Failed to match clause at .1." }
+  block; end block
+end
diff --git a/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-4.f90 b/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-4.f90
index 8f574740462..3abca5248f3 100644
--- a/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-4.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-4.f90
@@ -65,7 +65,7 @@ end do
 block
   x = 1
 end block
-! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.my77. \\\[len:4\\\]\\)severity\\(fatal\\) num_threads\\(dims\\(\\):77\\) shared\\(x\\) \\\[child fn" 1 "omplower" } }
+! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.my77. \\\[len:4\\\]\\) severity\\(fatal\\) num_threads\\(dims\\(\\):77\\) shared\\(x\\) \\\[child fn" 1 "omplower" } }
 ! { dg-final { scan-tree-dump-times "__builtin_GOMP_parallel \\(sub_._omp_fn.\[0-9\]+, &.omp_data_o.\[0-9\]+, 77, 0\\);" 1 "ompexp" } }
 
 
@@ -90,10 +90,10 @@ end block
 ! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-1\\) thread_limit\\(991\\) firstprivate\\(x\\) \\\[child fn" 1 "omplower" } }
 ! { dg-final { scan-tree-dump-times "#pragma omp teams num_teams\\(191, 993\\) thread_limit\\(991\\) shared\\(x\\)" 1 "omplower" } }
 
-!$omp teams thread_limit(relaxed : 1231) message("my1234") severity(warning)
+!$omp teams thread_limit(relaxed : 1231) message("my1234")
 block
 end block 
-! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.my1234. \\\[len:6\\\]\\) severity\\(warning\\) thread_limit\\(1231\\)" 1 "omplower" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.my1234. \\\[len:6\\\]\\) severity\\(fatal\\) thread_limit\\(1231\\)" 1 "omplower" } }
 ! { dg-final { scan-tree-dump-times "__builtin_GOMP_teams_reg \\(sub_._omp_fn.\[0-9\]+, 0B, 0, 1231, 0\\);" 1 "ompexp" } }
 
 end
diff --git a/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-5.f90 b/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-5.f90
index f0bf92a636a..9cde28a76ef 100644
--- a/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-5.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/spatial-dimensions-5.f90
@@ -4,13 +4,13 @@
 subroutine sub(x)
 implicit none
 integer :: x, i
-
+  ! while message applies to target+teams+parallel, severity only applies to parallel
 !$omp target teams distribute parallel do num_teams(11 : 22) thread_limit(strict,dims(3) : 11,12,13) num_threads(relaxed: 23,45,53) message("first") severity(warning)
 do i = 1,1
   x = 0
 end do
-! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-1\\) message\\(.first. \\\[len:5\\\]\\) severity\\(warning\\) thread_limit\\(strict,dims\\(\\):11, 12, 13\\) firstprivate\\(x\\)" 1 "gimple" } }
-! { dg-final { scan-tree-dump-times "#pragma omp teams num_teams\\(11, 22\\) thread_limit\\(strict,dims\\(\\):11, 12, 13\\) message\\(.first. \\\[len:5\\\]\\) severity\\(warning\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-1\\) message\\(.first. \\\[len:5\\\]\\) severity\\(fatal\\) thread_limit\\(strict,dims\\(\\):11, 12, 13\\) firstprivate\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams num_teams\\(11, 22\\) thread_limit\\(strict,dims\\(\\):11, 12, 13\\) message\\(.first. \\\[len:5\\\]\\) severity\\(fatal\\) shared\\(x\\)" 1 "gimple" } }
 ! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.first. \\\[len:5\\\]\\) severity\\(warning\\) num_threads\\(23, 45, 53\\) shared\\(x\\)" 1 "gimple" } }
 end
 
@@ -23,51 +23,51 @@ subroutine sub2(x)
 implicit none
 integer :: x, i
 
-!$omp target teams distribute parallel do num_teams(dims(4): 111,222,333, 324) thread_limit(relaxed : 11) num_threads(strict: 445,553) message("second") severity(fatal)
+!$omp target teams distribute parallel do num_teams(dims(4): 111,222,333, 324) thread_limit(relaxed : 11) num_threads(strict: 445,553) message("second")
 do i = 1,1
   x = 0
 end do
-! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-1\\) message\\(.second. \\\[len:6\\\]\\)severity\\(fatal\\) thread_limit\\(11\\) firstprivate\\(x\\)" 1 "gimple" } }
-! { dg-final { scan-tree-dump-times "#pragma omp teams num_teams\\(dims\\(\\):111, 222, 333, 324\\) thread_limit\\(11\\) message\\(.second. \\\[len:6\\\]\\)severity\\(fatal\\) shared\\(x\\)" 1 "gimple" } }
-! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.second. \\\[len:6\\\]\\)severity\\(fatal\\) num_threads\\(strict:445, 553\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-1\\) message\\(.second. \\\[len:6\\\]\\) severity\\(fatal\\) thread_limit\\(11\\) firstprivate\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams num_teams\\(dims\\(\\):111, 222, 333, 324\\) thread_limit\\(11\\) message\\(.second. \\\[len:6\\\]\\) severity\\(fatal\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.second. \\\[len:6\\\]\\) severity\\(fatal\\) num_threads\\(strict:445, 553\\) shared\\(x\\)" 1 "gimple" } }
 
 !$omp teams distribute parallel do num_teams(11 : 55) thread_limit(strict : 11) num_threads(relaxed: 23,45,53) message("third") severity(warning)
 do i = 1,1
   x = 0
 end do
-! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.third. \\\[len:5\\\]\\) severity\\(warning\\) num_teams\\(11, 55\\) thread_limit\\(strict:11\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.third. \\\[len:5\\\]\\) severity\\(fatal\\) num_teams\\(11, 55\\) thread_limit\\(strict:11\\) shared\\(x\\)" 1 "gimple" } }
 ! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.third. \\\[len:5\\\]\\) severity\\(warning\\) num_threads\\(23, 45, 53\\) shared\\(x\\)" 1 "gimple" } }
 
 !$omp teams distribute parallel do num_teams(dims(2): 1111,33) thread_limit(dims(3) : 11,3,480) num_threads(strict, dims(2): 445,553) message("fourth") severity(fatal)
 do i = 1,1
   x = 0
 end do
-! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.fourth. \\\[len:6\\\]\\)severity\\(fatal\\) num_teams\\(dims\\(\\):1111, 33\\) thread_limit\\(strict,dims\\(\\):11, 3, 480\\) shared\\(x\\)" 1 "gimple" } }
-! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.fourth. \\\[len:6\\\]\\)severity\\(fatal\\) num_threads\\(strict,dims\\(\\):445, 553\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.fourth. \\\[len:6\\\]\\) severity\\(fatal\\) num_teams\\(dims\\(\\):1111, 33\\) thread_limit\\(strict,dims\\(\\):11, 3, 480\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.fourth. \\\[len:6\\\]\\) severity\\(fatal\\) num_threads\\(strict,dims\\(\\):445, 553\\) shared\\(x\\)" 1 "gimple" } }
 
-!$omp target message("tgt1") severity(warning) thread_limit(strict : 1454)
+!$omp target message("tgt1") thread_limit(strict : 1454)
 block
   x = 0
 end block
-! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-2\\) message\\(.tgt1. \\\[len:4\\\]\\) severity\\(warning\\) thread_limit\\(strict:1454\\) firstprivate\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-2\\) message\\(.tgt1. \\\[len:4\\\]\\) severity\\(fatal\\) thread_limit\\(strict:1454\\) firstprivate\\(x\\)" 1 "gimple" } }
 
-!$omp target message("tgt2") severity(fatal) thread_limit(relaxed : 454)
+!$omp target message("tgt2") thread_limit(relaxed : 454)
 block
   x = 0
 end block
-! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-2\\) message\\(.tgt2. \\\[len:4\\\]\\)severity\\(fatal\\) thread_limit\\(454\\) firstprivate\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp target num_teams\\(-2\\) message\\(.tgt2. \\\[len:4\\\]\\) severity\\(fatal\\) thread_limit\\(454\\) firstprivate\\(x\\)" 1 "gimple" } }
 
-!$omp teams num_teams(14 : 34) message("teams") severity(fatal)
+!$omp teams num_teams(14 : 34) message("teams")
 block
   x = 0
 end block
-! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.teams. \\\[len:5\\\]\\)severity\\(fatal\\) num_teams\\(14, 34\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams message\\(.teams. \\\[len:5\\\]\\) severity\\(fatal\\) num_teams\\(14, 34\\) shared\\(x\\)" 1 "gimple" } }
 
-!$omp teams thread_limit(relaxed, dims(2): 514 , 384) severity(warning)
+!$omp teams thread_limit(relaxed, dims(2): 514 , 384)
 block
   x = 0
 end block
-! { dg-final { scan-tree-dump-times "#pragma omp teams severity\\(warning\\) thread_limit\\(dims\\(\\):514, 384\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp teams thread_limit\\(dims\\(\\):514, 384\\) shared\\(x\\)" 1 "gimple" } }
 
 !$omp parallel num_threads(relaxed, dims(2): 514 , 384) severity(warning)
 block
@@ -79,6 +79,6 @@ end block
 block
   x = 0
 end block
-! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.parallel. \\\[len:8\\\]\\)severity\\(fatal\\) num_threads\\(strict:847, 3523, 53\\) shared\\(x\\)" 1 "gimple" } }
+! { dg-final { scan-tree-dump-times "#pragma omp parallel message\\(.parallel. \\\[len:8\\\]\\) severity\\(fatal\\) num_threads\\(strict:847, 3523, 53\\) shared\\(x\\)" 1 "gimple" } }
 
 end
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index d3768befcd6..c252cd28bf6 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -612,7 +612,9 @@ enum omp_clause_code {
      If the string expr is not null terminated, the length needs to be
      stored in OMP_CLAUSE_MESSAGE_LEN.
      Note that the 'severity' clause is handled as flag to 'message':
-     OMP_CLAUSE_MESSAGE_SEVERITY_WARN.  */
+     OMP_CLAUSE_MESSAGE_SEVERITY_WARN; however, not all directives accepting the
+     message clause also accept the severity clause.  Without severity clause
+     (not permitted or not specified) the error action is error termination.  */
   OMP_CLAUSE_MESSAGE
 };
 
diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc
index 3c27d65e9e7..34fc7080783 100644
--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -854,8 +854,7 @@ dump_omp_clause (pretty_printer *pp, tree clause, int spc, dump_flags_t flags)
 	      pp_right_bracket (pp);
 	    }
 	  pp_right_paren (pp);
-	  if (OMP_CLAUSE_MESSAGE_SEVERITY_WARN (clause))
-	    pp_space (pp);
+	  pp_space (pp);
 	}
       if (OMP_CLAUSE_MESSAGE_SEVERITY_WARN (clause))
 	pp_string (pp, "severity(warning)");

Reply via email to