bad interaction between allocatable arrays and bind(C) subroutine with dimension(..) parameter

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

bad interaction between allocatable arrays and bind(C) subroutine with dimension(..) parameter

Gilles Gouaillardet-2
Folks,


The attached program evidences an issue when an allocatable array is
passed to

a bind(C) subroutine that takes a type(*), dimension(..) argument.


The expected output is :

OK: allocatable

OK: static

but with gcc 9.1.0, 9.2.0 and the latest master, the output is :

KO: allocatable

OK: static


Note the test is successful if the argument is declared as type(*),
dimension(*).


Incidentally, I also noted that if the test program is compiled with -g
-O0 and ran under gdb (I tried 7.6.1-110.el7 provided by CentOS 7),

the type of 'buf' as reported by the gdb whatis command changes after
the call to the bind(C) subroutine

22        CALL dummy (buf)
(gdb) whatis buf
type = integer(kind=4) (1)
(gdb) n
23        after = LOC(buf(1))
(gdb) whatis buf
type = integer(kind=4) (0:0)


FWIW, the test is successful with Intel compilers (I tried 2018.3 and
2019.3)


Could you please investigate this issue ?


Cheers,


Gilles


test.f90 (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: bad interaction between allocatable arrays and bind(C) subroutine with dimension(..) parameter

Gilles Gouaillardet-2
Hi Paul,


did you have any chance to investigate the issue I previously reported?


I would like to emphasize the test program I attached (that involves the
LOC() intrinsic) is a toy program

whose sole purpose is to evidence the issue.


I will be happy to provide a more close to real-life program if needed.

FWIW, I initially found this issue when testing MPI Fortran 2008
bindings with the TS interface

(long story short, the allocatable array becomes invalid after it is
passed as a parameter

to a MPI subroutine).


Cheers,


Gilles

On 8/20/2019 4:19 PM, Gilles Gouaillardet wrote:

> Folks,
>
>
> The attached program evidences an issue when an allocatable array is
> passed to
>
> a bind(C) subroutine that takes a type(*), dimension(..) argument.
>
>
> The expected output is :
>
> OK: allocatable
>
> OK: static
>
> but with gcc 9.1.0, 9.2.0 and the latest master, the output is :
>
> KO: allocatable
>
> OK: static
>
>
> Note the test is successful if the argument is declared as type(*),
> dimension(*).
>
>
> Incidentally, I also noted that if the test program is compiled with
> -g -O0 and ran under gdb (I tried 7.6.1-110.el7 provided by CentOS 7),
>
> the type of 'buf' as reported by the gdb whatis command changes after
> the call to the bind(C) subroutine
>
> 22        CALL dummy (buf)
> (gdb) whatis buf
> type = integer(kind=4) (1)
> (gdb) n
> 23        after = LOC(buf(1))
> (gdb) whatis buf
> type = integer(kind=4) (0:0)
>
>
> FWIW, the test is successful with Intel compilers (I tried 2018.3 and
> 2019.3)
>
>
> Could you please investigate this issue ?
>
>
> Cheers,
>
>
> Gilles
>
Reply | Threaded
Open this post in threaded view
|

Re: bad interaction between allocatable arrays and bind(C) subroutine with dimension(..) parameter

Paul Richard Thomas
Hi Gilles,

Something has gone wrong with the bounds. Before the call, lbound(buf)
is 1 and after it is 0.

I'll take a look.

Cheers

Paul

On Tue, 1 Oct 2019 at 05:15, Gilles Gouaillardet <[hidden email]> wrote:

>
> Hi Paul,
>
>
> did you have any chance to investigate the issue I previously reported?
>
>
> I would like to emphasize the test program I attached (that involves the
> LOC() intrinsic) is a toy program
>
> whose sole purpose is to evidence the issue.
>
>
> I will be happy to provide a more close to real-life program if needed.
>
> FWIW, I initially found this issue when testing MPI Fortran 2008
> bindings with the TS interface
>
> (long story short, the allocatable array becomes invalid after it is
> passed as a parameter
>
> to a MPI subroutine).
>
>
> Cheers,
>
>
> Gilles
>
> On 8/20/2019 4:19 PM, Gilles Gouaillardet wrote:
> > Folks,
> >
> >
> > The attached program evidences an issue when an allocatable array is
> > passed to
> >
> > a bind(C) subroutine that takes a type(*), dimension(..) argument.
> >
> >
> > The expected output is :
> >
> > OK: allocatable
> >
> > OK: static
> >
> > but with gcc 9.1.0, 9.2.0 and the latest master, the output is :
> >
> > KO: allocatable
> >
> > OK: static
> >
> >
> > Note the test is successful if the argument is declared as type(*),
> > dimension(*).
> >
> >
> > Incidentally, I also noted that if the test program is compiled with
> > -g -O0 and ran under gdb (I tried 7.6.1-110.el7 provided by CentOS 7),
> >
> > the type of 'buf' as reported by the gdb whatis command changes after
> > the call to the bind(C) subroutine
> >
> > 22        CALL dummy (buf)
> > (gdb) whatis buf
> > type = integer(kind=4) (1)
> > (gdb) n
> > 23        after = LOC(buf(1))
> > (gdb) whatis buf
> > type = integer(kind=4) (0:0)
> >
> >
> > FWIW, the test is successful with Intel compilers (I tried 2018.3 and
> > 2019.3)
> >
> >
> > Could you please investigate this issue ?
> >
> >
> > Cheers,
> >
> >
> > Gilles
> >



--
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein