public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR)
@ 2015-07-22 20:07 brtnfld at hdfgroup dot org
  2015-07-22 20:08 ` [Bug fortran/66973] " brtnfld at hdfgroup dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: brtnfld at hdfgroup dot org @ 2015-07-22 20:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

            Bug ID: 66973
           Summary: Incorrect resolution of generic interface with
                    TYPE(C_PTR)
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: brtnfld at hdfgroup dot org
  Target Milestone: ---

Created attachment 36035
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36035&action=edit
H5Tff.F90 -- contains the module

The following sequence picks the f90 interface, when it should pick the


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
@ 2015-07-22 20:08 ` brtnfld at hdfgroup dot org
  2015-07-22 20:11 ` brtnfld at hdfgroup dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: brtnfld at hdfgroup dot org @ 2015-07-22 20:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

--- Comment #1 from Scot Breitenfeld <brtnfld at hdfgroup dot org> ---
Created attachment 36036
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36036&action=edit
fortranlib_test_F03, main program


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
  2015-07-22 20:08 ` [Bug fortran/66973] " brtnfld at hdfgroup dot org
@ 2015-07-22 20:11 ` brtnfld at hdfgroup dot org
  2015-07-22 20:15 ` brtnfld at hdfgroup dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: brtnfld at hdfgroup dot org @ 2015-07-22 20:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

--- Comment #2 from Scot Breitenfeld <brtnfld at hdfgroup dot org> ---
The following sequence picks the f90 interface, when it should pick the f03
(TYPE(C_PTR)) interface.

gfortran -c H5Tff.F90
gfortran fortranlib_test_F03.f90 -o H5Tff.o

The program prints: 

PRINT*,'Inside pick_f90'


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
  2015-07-22 20:08 ` [Bug fortran/66973] " brtnfld at hdfgroup dot org
  2015-07-22 20:11 ` brtnfld at hdfgroup dot org
@ 2015-07-22 20:15 ` brtnfld at hdfgroup dot org
  2015-07-22 20:30 ` brtnfld at hdfgroup dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: brtnfld at hdfgroup dot org @ 2015-07-22 20:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

--- Comment #3 from Scot Breitenfeld <brtnfld at hdfgroup dot org> ---
(In reply to Scot Breitenfeld from comment #2)
> The following sequence picks the f90 interface, when it should pick the f03
> (TYPE(C_PTR)) interface.
> 
> gfortran -c H5Tff.F90
> gfortran fortranlib_test_F03.f90 -o H5Tff.o
> 
> The program prints: 
> 
> PRINT*,'Inside pick_f90'

I meant gfortran fortranlib_test_F03.f90 H5Tff.o


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
                   ` (2 preceding siblings ...)
  2015-07-22 20:15 ` brtnfld at hdfgroup dot org
@ 2015-07-22 20:30 ` brtnfld at hdfgroup dot org
  2015-07-22 21:37 ` dominiq at lps dot ens.fr
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: brtnfld at hdfgroup dot org @ 2015-07-22 20:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

--- Comment #4 from Scot Breitenfeld <brtnfld at hdfgroup dot org> ---
The work around is instead to do:

PROGRAM main
  USE H5T
  IMPLICIT NONE
  REAL, TARGET :: val
  TYPE(C_PTR) :: f_ptr
  f_ptr = C_LOC(val)
  CALL pickone(f_ptr)
END PROGRAM main


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
                   ` (3 preceding siblings ...)
  2015-07-22 20:30 ` brtnfld at hdfgroup dot org
@ 2015-07-22 21:37 ` dominiq at lps dot ens.fr
  2015-07-22 21:55 ` brtnfld at hdfgroup dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-07-22 21:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-07-22
     Ever confirmed|0                           |1

--- Comment #5 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed when the test is made of two files. If I merge the two files in one,
I get

 Inside pick_f03

Tested with 4.9 to trunk (6.0).


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
                   ` (4 preceding siblings ...)
  2015-07-22 21:37 ` dominiq at lps dot ens.fr
@ 2015-07-22 21:55 ` brtnfld at hdfgroup dot org
  2023-04-12 18:48 ` anlauf at gcc dot gnu.org
  2023-04-12 19:42 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: brtnfld at hdfgroup dot org @ 2015-07-22 21:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

--- Comment #6 from Scot Breitenfeld <brtnfld at hdfgroup dot org> ---
it also works if you add USE ISO_C_BINDING to the main program:

PROGRAM main
  USE ISO_C_BINDING
  USE H5T
  IMPLICIT NONE
  REAL, TARGET :: val
  CALL pickone(C_LOC(val))
END PROGRAM main


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
                   ` (5 preceding siblings ...)
  2015-07-22 21:55 ` brtnfld at hdfgroup dot org
@ 2023-04-12 18:48 ` anlauf at gcc dot gnu.org
  2023-04-12 19:42 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-04-12 18:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2015-07-22 00:00:00         |2023-4-12
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #7 from anlauf at gcc dot gnu.org ---
This issue still persists at r13-7146 when using separate files for the
module and the main program.

gfortran's behavior is fragile: using e.g.

  USE ISO_C_BINDING, only: C_PTR

in the module makes the code work as desired (needs USE ISO_C_BINDING in the
main).

However, using

  USE ISO_C_BINDING, only: C_PTR, C_LOC

in the module breaks it again.

The behavior also depends on the order of USE statements in the main:

  USE H5T
  USE ISO_C_BINDING

differs from

  USE ISO_C_BINDING
  USE H5T

which should not happen...

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/66973] Incorrect resolution of generic interface with TYPE(C_PTR)
  2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
                   ` (6 preceding siblings ...)
  2023-04-12 18:48 ` anlauf at gcc dot gnu.org
@ 2023-04-12 19:42 ` anlauf at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-04-12 19:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66973

--- Comment #8 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #7)
> The behavior also depends on the order of USE statements in the main:
> 
>   USE H5T
>   USE ISO_C_BINDING
> 
> differs from
> 
>   USE ISO_C_BINDING
>   USE H5T
> 
> which should not happen...

A workaround is to use a temporary of type(c_ptr) for the actual argument:

  type(c_ptr) :: ptr
  CALL pickone(ptr)

This works for me.

Possibly the issue is with the resolution of (the type of?) C_LOC ...

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-04-12 19:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-22 20:07 [Bug fortran/66973] New: Incorrect resolution of generic interface with TYPE(C_PTR) brtnfld at hdfgroup dot org
2015-07-22 20:08 ` [Bug fortran/66973] " brtnfld at hdfgroup dot org
2015-07-22 20:11 ` brtnfld at hdfgroup dot org
2015-07-22 20:15 ` brtnfld at hdfgroup dot org
2015-07-22 20:30 ` brtnfld at hdfgroup dot org
2015-07-22 21:37 ` dominiq at lps dot ens.fr
2015-07-22 21:55 ` brtnfld at hdfgroup dot org
2023-04-12 18:48 ` anlauf at gcc dot gnu.org
2023-04-12 19:42 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).