Improves the diagnostics for the deprecated form of the linear clause, now providing a hint for the contemporary syntax. Additionally modifies the relevant test to reflect the verbiage change.
Built/tested x86_64-pc-linux-gnu.
From 67cbf76480615fabceb0e8d07c9ba64ccdc70af2 Mon Sep 17 00:00:00 2001 From: supers1ngular <[email protected]> Date: Sat, 13 Dec 2025 10:28:31 -0800 Subject: [PATCH] [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 af89c87b0ab..c8b54b2387b 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -3466,11 +3466,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) @@ -3494,6 +3489,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
