https://gcc.gnu.org/g:816931db9e1301f05ae9075bb367d5cda92ae6c8
commit 816931db9e1301f05ae9075bb367d5cda92ae6c8 Author: Tobias Burnus <[email protected]> Date: Tue Jun 9 13:58:03 2026 +0200 Fortran/OpenMP: Improve declare-reduction diagnostic Change the diagnostic for the ambiguity check for 'omp declare reduction' to actually output the reduction operator/idenfier and the type to which this reduction applies to. gcc/fortran/ChangeLog: * module.cc (load_omp_udrs): Improve reduction diagnostic output. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/declare-reduction-1.f90: New test. (cherry picked from commit fd268b83ffb58ae700380e1e52af279f782fdb38) Diff: --- gcc/fortran/module.cc | 13 ++++---- .../gfortran.dg/gomp/declare-reduction-1.f90 | 39 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc index 04ddf6b4476b..38c9b295f6b9 100644 --- a/gcc/fortran/module.cc +++ b/gcc/fortran/module.cc @@ -76,6 +76,7 @@ along with GCC; see the file COPYING3. If not see #include "parse.h" /* FIXME */ #include "constructor.h" #include "cpp.h" +#include "diagnostic-core.h" #include "scanner.h" #include <zlib.h> @@ -5443,12 +5444,12 @@ load_omp_udrs (void) pointer_info *p = get_integer (atom_int); if (strcmp (p->u.rsym.module, udr->omp_out->module)) { - gfc_error ("Ambiguous !$OMP DECLARE REDUCTION from " - "module %s at %L", - p->u.rsym.module, &gfc_current_locus); - gfc_error ("Previous !$OMP DECLARE REDUCTION from module " - "%s at %L", - udr->omp_out->module, &udr->where); + gfc_error ("Ambiguous !$OMP DECLARE REDUCTION %qs for type %qs " + "from module %qs at %L", udr->name, + gfc_typename (&ts), module_name, &gfc_current_locus); + inform (gfc_get_location (&udr->where), + "Previous !$OMP DECLARE REDUCTION from module %qs", + udr->omp_out->module); } skip_list (1); continue; diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-reduction-1.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-reduction-1.f90 new file mode 100644 index 000000000000..32f00aaf2b0a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/declare-reduction-1.f90 @@ -0,0 +1,39 @@ +! { dg-do compile } + +module one + implicit none + type t + integer :: x + end type t +end module + +module two + use one + implicit none + !$omp declare reduction(+ : t : omp_out%x = omp_out%x + omp_in%x) initializer (omp_priv%x = 0) +end module + +module three + use one + implicit none + !$omp declare reduction(+ : t : omp_out%x = omp_out%x + omp_in%x) initializer (omp_priv%x = 0) +end module + +subroutine sub2 + use two ! { dg-note "Previous !.OMP DECLARE REDUCTION from module 'two'" } + use three ! { dg-error "Ambiguous !.OMP DECLARE REDUCTION 'operator \\+' for type 'TYPE\\(t\\)' from module 'three' at .1." } + implicit none + type(t) :: var(3), sum + integer :: i + + var(:)%x = [1,2,3] + sum%x = 0 + + !$omp parallel do reduction(+: sum) + do i = 1, 3 + sum%x = sum%x + var(i)%x + end do +end + +call sub2 +end
