[committed] openmp: Improve Fortran Diagnostics for Linear Clause

Gio T <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <CACSSYh8UGPGYZ4OoR2i+hQ3=hSgWGHYvC8UJhVz_ZbrGbpD2Cw@mail.gmail.com>
This patch was committed:
https://gcc.gnu.org/pipermail/gcc-patches/2025-December/703598.html
with the feedback from:
https://gcc.gnu.org/pipermail/gcc-patches/2025-December/704113.html
implemented, being swapping the single quotes for the bold
formatting. Modified patch included as an attachment.

Built/tested x86_64-pc-linux-gnu.
0001-openmp-Improve-Fortran-Diagnostics-for-Linear-Clause.patch (text/x-patch, 4.1 KB)
From cdb15b390035fc4843e11363bcc4e0eff419d6a3 Mon Sep 17 00:00:00 2001
From: supers1ngular <[email protected]>
Date: Mon, 5 Jan 2026 17:09:02 -0800
Subject: [PATCH] openmp: Improve Fortran Diagnostics for Linear Clause

This patch improves diagnostics for the linear clause,
providing a more accurate and intuitive recommendation
for remediation if the deprecated syntax is used.
Additionally updates the relevant test to reflect the
changed verbiage of the warning.

gcc/fortran/ChangeLog:

	* openmp.cc (gfc_match_omp_clauses): New diagnostic logic.

libgomp/ChangeLog:

	* testsuite/libgomp.fortran/pr84418-1.f90: Fix verbiage of
	dg-warning to reflect updated warning.
---
 gcc/fortran/openmp.cc                         | 51 +++++++++++++++++--
 .../testsuite/libgomp.fortran/pr84418-1.f90   |  3 +-
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index dddb42f2d99..5823ac41fa5 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -3481,11 +3481,6 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 		  gfc_current_locus = old_loc;
 		  break;
 		}
-	      if (old_linear_modifier)
-		gfc_warning (OPT_Wdeprecated_openmp,
-			     "Specification of the list items as arguments to "
-			     "the modifiers at %L is deprecated since "
-			     "OpenMP 5.2", &saved_loc);
 	      if (linear_op != OMP_LINEAR_DEFAULT)
 		{
 		  if (gfc_match (" :") == MATCH_YES)
@@ -3509,6 +3504,52 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
 		      goto error;
 		    }
 		}
+	      if (old_linear_modifier)
+		{
+		  char var_names[512]{};
+		  int count, offset = 0;
+		  for (gfc_omp_namelist *n = *head; n; n = n->next)
+		    {
+		      if (!n->next)
+			count = snprintf (var_names + offset,
+					  sizeof (var_names) - offset,
+					  "%s", n->sym->name);
+		      else
+			count = snprintf (var_names + offset,
+					  sizeof (var_names) - offset,
+					  "%s, ", n->sym->name);
+		      if (count < 0 || count >= ((int)sizeof (var_names))
+						- offset)
+			{
+			  snprintf (var_names, 512, "%s, ..., ",
+				    (*head)->sym->name);
+			  while (n->next)
+			    n = n->next;
+			  offset = strlen (var_names);
+			  snprintf (var_names + offset,
+				    sizeof (var_names) - offset,
+				    "%s", n->sym->name);
+			  break;
+			}
+		      offset += count;
+		    }
+		  char *var_names_for_warn = var_names;
+		  const char *op_name;
+		  switch (linear_op)
+		    {
+		      case OMP_LINEAR_REF: op_name = "ref"; break;
+		      case OMP_LINEAR_VAL: op_name = "val"; break;
+		      case OMP_LINEAR_UVAL: op_name = "uval"; break;
+		      default: gcc_unreachable ();
+		    }
+		  gfc_warning (OPT_Wdeprecated_openmp,
+			       "Specification of the list items as "
+			       "arguments to the modifiers at %L is "
+			       "deprecated; since OpenMP 5.2, use "
+			       "%<linear(%s : %s%s)%>", &saved_loc,
+			       var_names_for_warn, op_name,
+			       step == nullptr ? "" : ", step(...)");
+		}
 	      else if (end_colon)
 		{
 		  bool has_error = false;
diff --git a/libgomp/testsuite/libgomp.fortran/pr84418-1.f90 b/libgomp/testsuite/libgomp.fortran/pr84418-1.f90
index 65dae5d0b0b..b86dfe5d92a 100644
--- a/libgomp/testsuite/libgomp.fortran/pr84418-1.f90
+++ b/libgomp/testsuite/libgomp.fortran/pr84418-1.f90
@@ -3,6 +3,7 @@
 ! { dg-options "-fno-inline" }
 ! { dg-additional-options "-msse2" { target sse2_runtime } }
 ! { dg-additional-options "-mavx" { target avx_runtime } }
+! { dg-warning "Specification of the list items as arguments to the modifiers at \\(1\\) is deprecated; since OpenMP 5.2, use 'linear\\(x, y : ref\\)' \\\[-Wdeprecated-openmp\\\]" "" { target *-*-* } 24 }
 
   real :: a(1024), b(1024), c(1024)
   integer :: i
@@ -20,7 +21,7 @@
 contains
   real function foo (x, y)
     real :: x, y
-    !$omp declare simd linear (ref (x, y)) ! { dg-warning "Specification of the list items as arguments to the modifiers at \\(1\\) is deprecated since OpenMP 5.2 \\\[-Wdeprecated-openmp\\\]" }
+    !$omp declare simd linear (ref (x, y))
     foo = x + y
   end function
 end
-- 
2.51.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.