[gcc r16-6513] openmp: Improve Fortran Diagnostics for Linear Clause
Gio T
supers1ngular@gcc.gnu.org
Tue Jan 6 01:25:51 GMT 2026
https://gcc.gnu.org/g:cdb15b390035fc4843e11363bcc4e0eff419d6a3
commit r16-6513-gcdb15b390035fc4843e11363bcc4e0eff419d6a3
Author: supers1ngular <supers1ngular@baylibre.com>
Date: Mon Jan 5 17:09:02 2026 -0800
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.
Diff:
---
gcc/fortran/openmp.cc | 51 ++++++++++++++++++++++---
libgomp/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 dddb42f2d998..5823ac41fa51 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 65dae5d0b0b0..b86dfe5d92ad 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
More information about the Gcc-cvs
mailing list