[committed] Fortran/OpenMP: Improve declare-reduction diagnostic

Tobias Burnus <[email protected]> Tue, 9 Jun 2026 14:03:06 +0200
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
GCC currently prints the not so helpful:

    24 |   use three
       |      1
Error: Ambiguous !$OMP DECLARE REDUCTION from module three at (1)
    23 |   use two
       |      1
Error: Previous !$OMP DECLARE REDUCTION from module two at (1)


That's okay if there is only a single reduction - but if there
are multiple ...


Solution: Output operator and type in addition. I also switched to
'Note:' to make the relation error + associated clearer compared
to having two 'errors'.

    24 |   use three
       |      1
Error: Ambiguous !$OMP DECLARE REDUCTION ‘operator +’ for type ‘TYPE(t)’ from module ‘three’ at (1)
decl-red2.f90:23:6:
    23 |   use two
       |      1
note: Previous !$OMP DECLARE REDUCTION from module ‘two’


Committed as Rev. r17-1443-gfd268b83ffb58a

Are there any (post-commit) comments and remarks?

Tobias

PS: I guess we should eventually add 'gfc_inform' with buffer handling;
additionally 'note:' should be 'Note:' (→ gfc-diagnostic.def).

PPS: The code doesn't handle derived-type renaming. That's the same issue
as the 'declare mapper' patch that I will sent in a moment and will have to
be dealt as followup to both declare mapper/reduction.