[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 chrisonian at gmail dot com changed: What|Removed |Added CC||chrisonian at gmail dot com --- Comment #1 from chrisonian at gmail dot com --- This bug is still present in versions 8.3.0, 9.3.0, 10.1.0 Testing on Cori (NERSC): module load gcc/8.3.0 or module load gcc/9.3.0 or module load gcc/10.1.0 The result is the same: gfortran test.f90 test.f90:30:8: y = sqrt(x) 1 Error: Name 'sqrt' at (1) is an ambiguous reference to 'sqrt' from module '(intrinsic)'
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 kargl at gcc dot gnu.org changed: What|Removed |Added Priority|P3 |P4 CC||kargl at gcc dot gnu.org --- Comment #2 from kargl at gcc dot gnu.org --- (In reply to chrisonian from comment #1) > This bug is still present in versions 8.3.0, 9.3.0, 10.1.0 > > The bug likely does not effect anyone that contributes code to GCC. Someday someone might look at this bug. Fortunately, there is a trivial work around, e.g., change the generic-name from 'sqrt' to 'root'. If one does this and then looks at the contents of mod2.mod, one see the only difference shown here. Perhaps, module.c needs to be fixed to record the generic interface. diff -u zxc1 zxc2 --- zxc12021-04-12 14:29:48.345332000 -0700 +++ zxc22021-04-12 14:30:04.774051000 -0700 @@ -4,7 +4,7 @@ () -(('pair' 'mod2' 2) ('root' 'mod2' 3 4)) +(('pair' 'mod2' 2) ('sqrt' '(intrinsic)' 3 4)) ()
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 anlauf at gcc dot gnu.org changed: What|Removed |Added CC||anlauf at gcc dot gnu.org --- Comment #3 from anlauf at gcc dot gnu.org --- (In reply to kargl from comment #2) > The bug likely does not effect anyone that contributes code > to GCC. It does not affect me, but that is due my coding style (using public/private). > Fortunately, > there is a trivial work around, e.g., change the generic-name > from 'sqrt' to 'root'. Please don't do that. I already have my own generic root()... However, why in the world does an intrinsic need to show up in the module file in the first place? Consider: module mod1 implicit none real, parameter :: z = sqrt (0.0) end module mod1 Is there a reason why the intrinsic should not be prevented from occurring in the module file?
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #4 from anlauf at gcc dot gnu.org --- The following patch regtests ok and fixes the testcase: diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 4db0a3ac76d..b4b7b437f86 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -6218,6 +6218,9 @@ write_symtree (gfc_symtree *st) if (check_unique_name (st->name)) return; + if (strcmp (sym->module, "(intrinsic)") == 0) +return; + p = find_pointer (sym); if (p == NULL) gfc_internal_error ("write_symtree(): Symbol not written"); It even fixes the slightly reduced & refined testcase: module mod1 implicit none real, parameter :: z = sqrt (0.0) end module mod1 module mod2 implicit none type t real :: a = 0. end type interface sqrt module procedure sqrt end interface contains function sqrt (a) type(t), intent(in) :: a type(t) :: sqrt sqrt% a = a% a end function sqrt end module mod2 program test use mod1 use mod2 implicit none type(t) :: x, y y = sqrt (x) end program test
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #5 from Steve Kargl --- On Tue, Apr 13, 2021 at 08:49:35PM +, anlauf at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 > > --- Comment #4 from anlauf at gcc dot gnu.org --- > The following patch regtests ok and fixes the testcase: > > diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c > index 4db0a3ac76d..b4b7b437f86 100644 > --- a/gcc/fortran/module.c > +++ b/gcc/fortran/module.c > @@ -6218,6 +6218,9 @@ write_symtree (gfc_symtree *st) >if (check_unique_name (st->name)) > return; > > + if (strcmp (sym->module, "(intrinsic)") == 0) > +return; > + >p = find_pointer (sym); >if (p == NULL) > gfc_internal_error ("write_symtree(): Symbol not written"); > > > It even fixes the slightly reduced & refined testcase: > Harald, if this survives regression testing, it might be appropriate to commit. The only issue I can think of is procedure pointers. I don't use them, but if one can point at sqrt (or dsqrt, i.e., with specific vs generic name), then is [d]sqrt needed to be written into the module?
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #6 from anlauf at gcc dot gnu.org --- Steve, can you give an example for the procedure pointer case you mentioned? I played a bit, but the only valid code that I can think of did not produce a reference to sqrt in such a way that it needs to show up in the mod. Extended testcase that compiles and also uses a procedure pointer to sqrt(): ! { dg-do compile } ! PR63797 - Bogus ambiguous reference to 'sqrt' module mod1 implicit none real, parameter :: z = sqrt (0.0) real:: w = sqrt (1.0) interface pure real function sqrt_ifc (x) real, intent(in) :: x end function sqrt_ifc end interface contains pure function myroot () result (f) procedure(sqrt_ifc), pointer :: f intrinsic :: sqrt f => sqrt end function myroot end module mod1 module mod2 implicit none type t real :: a = 0. end type interface sqrt module procedure sqrt end interface contains function sqrt (a) type(t), intent(in) :: a type(t) :: sqrt sqrt% a = a% a end function sqrt end module mod2 program test use mod1 use mod2 implicit none type(t) :: x, y procedure(sqrt_ifc), pointer :: root root => myroot () y= sqrt (x) y% a = sqrt (x% a) + z - w + root (x% a) end program test
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #7 from Steve Kargl --- On Wed, Apr 14, 2021 at 08:43:50PM +, anlauf at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 > > --- Comment #6 from anlauf at gcc dot gnu.org --- > Steve, can you give an example for the procedure pointer case you mentioned? > I played a bit, but the only valid code that I can think of did not produce > a reference to sqrt in such a way that it needs to show up in the mod. > > Extended testcase that compiles and also uses a procedure pointer to sqrt(): > Your testcase is what I first thought about, but didn't try to write. The only other instance that I might be concerned about is module aaa abstract interface function real_func (x) real :: real_func real, intent (in) :: x end function real_func end interface procedure(real_func), pointer :: bah => sqrt end module aaa which looks like a default initialization. Does sqrt need to be recorded into the module? If not, then your patch is probably ok.
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #8 from anlauf at gcc dot gnu.org --- (In reply to Steve Kargl from comment #7) > which looks like a default initialization. Does sqrt need to be > recorded into the module? If not, then your patch is probably ok. My patch actually does not have any affect on the module file generated for your testcase. I'll add it to my testcase and submit.
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #9 from anlauf at gcc dot gnu.org --- Patch: https://gcc.gnu.org/pipermail/fortran/2021-April/055935.html
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #10 from CVS Commits --- The master branch has been updated by Harald Anlauf : https://gcc.gnu.org/g:d264194c1069fbcd129222f86455137f29a5c6fd commit r11-8218-gd264194c1069fbcd129222f86455137f29a5c6fd Author: Harald Anlauf Date: Fri Apr 16 16:24:31 2021 +0200 PR fortran/63797 - Bogus ambiguous reference to 'sqrt' The interface of an intrinsic procedure is automatically explicit. Do not write it to the module file to prevent wrong ambiguities on USE. gcc/fortran/ChangeLog: PR fortran/63797 * module.c (write_symtree): Do not write interface of intrinsic procedure to module file for F2003 and newer. gcc/testsuite/ChangeLog: PR fortran/63797 * gfortran.dg/pr63797.f90: New test. Co-authored-by: Paul Thomas
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 --- Comment #11 from CVS Commits --- The releases/gcc-10 branch has been updated by Harald Anlauf : https://gcc.gnu.org/g:aff57bcebe534b1d92f78bdfb89a4001a6d12af2 commit r10-9712-gaff57bcebe534b1d92f78bdfb89a4001a6d12af2 Author: Harald Anlauf Date: Fri Apr 16 16:24:31 2021 +0200 PR fortran/63797 - Bogus ambiguous reference to 'sqrt' The interface of an intrinsic procedure is automatically explicit. Do not write it to the module file to prevent wrong ambiguities on USE. gcc/fortran/ChangeLog: PR fortran/63797 * module.c (write_symtree): Do not write interface of intrinsic procedure to module file for F2003 and newer. gcc/testsuite/ChangeLog: PR fortran/63797 * gfortran.dg/pr63797.f90: New test. Co-authored-by: Paul Thomas (cherry picked from commit d264194c1069fbcd129222f86455137f29a5c6fd)
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 anlauf at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #12 from anlauf at gcc dot gnu.org --- Fixed on mainline for gcc-11, and backported to 10-branch as suggested by Paul. Closing. Thanks for the report!
[Bug fortran/63797] Bogus ambiguous reference to 'sqrt'
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63797 Tobias Burnus changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2014-11-09 CC||pault at gcc dot gnu.org Ever confirmed|0 |1 Known to fail||4.4.5, 4.8.3, 5.0