[Bug fortran/69298] Array finalisers seem to be given the wrong array when the array is a member variable.

2016-10-24 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69298

--- Comment #5 from Paul Thomas  ---
(In reply to Dominique d'Humieres from comment #3)
> > Created attachment 37448 [details]
> > Self-contained variant
> 
> With n=3, the output of the attached test is
> 
> Initialising stuff_type 4
> Finalising stuff_type 0
> ...
> ---
> Initialising test_type
> Initialising stuff_type 4
> Finalising stuff_type 0
> Copy initialiser 4 4
> Initialising stuff_type 1
> Finalising stuff_type 0
> Copy initialiser 1 1
> Initialising stuff_type 2
> Finalising stuff_type 0
> Copy initialiser 2 2
> Initialising stuff_type 3
> Finalising stuff_type 0
> Copy initialiser 3 3
> Finalising stuff_type 4
> Copy initialiser 4 4
> thing 10
> Finalising stuff_type 4
> 
> Program received signal SIGSEGV: Segmentation fault - invalid memory
> reference.
> 
> Changing 'n' to 2 or 4, gives respectively
> 
> ...
> ---
> Initialising test_type
> Initialising stuff_type 4
> Finalising stuff_type 1342972320
> Copy initialiser 4 4
> Initialising stuff_type 1
> Finalising stuff_type 32767
> Copy initialiser 1 1
> Initialising stuff_type 2
> Finalising stuff_type 263453344
> Copy initialiser 2 2
> Finalising stuff_type 4
> Copy initialiser 4 4
> thing 7
> Finalising stuff_type 4
> 
> Program received signal SIGSEGV: Segmentation fault - invalid memory
> reference.
> 
> and
> 
> ...
> Initialising test_type
> Initialising stuff_type 4
> Finalising stuff_type 107478528
> Copy initialiser 4 4
> Initialising stuff_type 1
> Finalising stuff_type 1
> Copy initialiser 1 1
> Initialising stuff_type 2
> Finalising stuff_type 5120
> Copy initialiser 2 2
> Initialising stuff_type 3
> Finalising stuff_type 0
> Copy initialiser 3 3
> Initialising stuff_type 4
> Finalising stuff_type 1501114256
> Copy initialiser 4 4
> Finalising stuff_type 4
> Copy initialiser 4 4
> thing 14
> Finalising stuff_type 4
> 
> where the nonzero values changed between different runs.

For the record, since I have spent an hour or two investigating this tonight:

__final_test_mod_Test_type has, towards the end


{
  struct array0_stuff_type desc.32;

  desc.32.dtype = 296;
  desc.32.data = (void * restrict) >thing;
  __final_stuff_mod_Stuff_type ();
}
{
  struct array1_stuff_type parm.33;

  parm.33.dtype = 297;
  parm.33.dim[0].lbound = 1;
  parm.33.dim[0].ubound = 3;
  parm.33.dim[0].stride = 1;
  parm.33.data = (void *) >things[0];
  parm.33.offset = -1;
  __final_stuff_mod_Stuff_type ();
}

whereas the prototype for the 'stuff' finalization is

__final_stuff_mod_Stuff_type (struct array7_stuff_type & restrict array,
integer(kind=8) byte_stride, logical(kind=1) fini_coarray)


That is to say that two actual arguments are missing.

Since this contains
  if (byte_stride == 4)
{
  {
static integer(kind=8) C.3513 = 4;

stuff_1d_finaliser ((struct array7_stuff_type *) array,
);
  }
}

It seems difficult to understand how stuff_1d_finaliser is getting called at
all!

I'll come back to this when I can.

Paul

[Bug fortran/69298] Array finalisers seem to be given the wrong array when the array is a member variable.

2016-10-24 Thread pault at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69298

Paul Thomas  changed:

   What|Removed |Added

 CC||pault at gcc dot gnu.org

--- Comment #4 from Paul Thomas  ---
(In reply to Dominique d'Humieres from comment #3)
> > Created attachment 37448 [details]
> > Self-contained variant
> 
> With n=3, the output of the attached test is
> 
> Initialising stuff_type 4
> Finalising stuff_type 0
> ...
> ---
> Initialising test_type
> Initialising stuff_type 4
> Finalising stuff_type 0
> Copy initialiser 4 4
> Initialising stuff_type 1
> Finalising stuff_type 0
> Copy initialiser 1 1
> Initialising stuff_type 2
> Finalising stuff_type 0
> Copy initialiser 2 2
> Initialising stuff_type 3
> Finalising stuff_type 0
> Copy initialiser 3 3
> Finalising stuff_type 4
> Copy initialiser 4 4
> thing 10
> Finalising stuff_type 4
> 
> Program received signal SIGSEGV: Segmentation fault - invalid memory
> reference.
> 
> Changing 'n' to 2 or 4, gives respectively
> 
> ...
> ---
> Initialising test_type
> Initialising stuff_type 4
> Finalising stuff_type 1342972320
> Copy initialiser 4 4
> Initialising stuff_type 1
> Finalising stuff_type 32767
> Copy initialiser 1 1
> Initialising stuff_type 2
> Finalising stuff_type 263453344
> Copy initialiser 2 2
> Finalising stuff_type 4
> Copy initialiser 4 4
> thing 7
> Finalising stuff_type 4
> 
> Program received signal SIGSEGV: Segmentation fault - invalid memory
> reference.
> 
> and
> 
> ...
> Initialising test_type
> Initialising stuff_type 4
> Finalising stuff_type 107478528
> Copy initialiser 4 4
> Initialising stuff_type 1
> Finalising stuff_type 1
> Copy initialiser 1 1
> Initialising stuff_type 2
> Finalising stuff_type 5120
> Copy initialiser 2 2
> Initialising stuff_type 3
> Finalising stuff_type 0
> Copy initialiser 3 3
> Initialising stuff_type 4
> Finalising stuff_type 1501114256
> Copy initialiser 4 4
> Finalising stuff_type 4
> Copy initialiser 4 4
> thing 14
> Finalising stuff_type 4
> 
> where the nonzero values changed between different runs.

For the record, since I have spent an hour or two investigating this tonight:

__final_test_mod_Test_type has, towards the end


{
  struct array0_stuff_type desc.32;

  desc.32.dtype = 296;
  desc.32.data = (void * restrict) >thing;
  __final_stuff_mod_Stuff_type ();
}
{
  struct array1_stuff_type parm.33;

  parm.33.dtype = 297;
  parm.33.dim[0].lbound = 1;
  parm.33.dim[0].ubound = 3;
  parm.33.dim[0].stride = 1;
  parm.33.data = (void *) >things[0];
  parm.33.offset = -1;
  __final_stuff_mod_Stuff_type ();
}

whereas the prototype for the 'stuff' finalization is

__final_stuff_mod_Stuff_type (struct array7_stuff_type & restrict array,
integer(kind=8) byte_stride, logical(kind=1) fini_coarray)


That is to say that two actual arguments are missing.

Since this contains
  if (byte_stride == 4)
{
  {
static integer(kind=8) C.3513 = 4;

stuff_1d_finaliser ((struct array7_stuff_type *) array,
);
  }
}

It seems difficult to understand how stuff_1d_finaliser is getting called at
all!

I'll come back to this when I can.

Paul

[Bug fortran/69298] Array finalisers seem to be given the wrong array when the array is a member variable.

2016-01-25 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69298

--- Comment #3 from Dominique d'Humieres  ---
> Created attachment 37448 [details]
> Self-contained variant

With n=3, the output of the attached test is

Initialising stuff_type 4
Finalising stuff_type 0
...
---
Initialising test_type
Initialising stuff_type 4
Finalising stuff_type 0
Copy initialiser 4 4
Initialising stuff_type 1
Finalising stuff_type 0
Copy initialiser 1 1
Initialising stuff_type 2
Finalising stuff_type 0
Copy initialiser 2 2
Initialising stuff_type 3
Finalising stuff_type 0
Copy initialiser 3 3
Finalising stuff_type 4
Copy initialiser 4 4
thing 10
Finalising stuff_type 4

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Changing 'n' to 2 or 4, gives respectively

...
---
Initialising test_type
Initialising stuff_type 4
Finalising stuff_type 1342972320
Copy initialiser 4 4
Initialising stuff_type 1
Finalising stuff_type 32767
Copy initialiser 1 1
Initialising stuff_type 2
Finalising stuff_type 263453344
Copy initialiser 2 2
Finalising stuff_type 4
Copy initialiser 4 4
thing 7
Finalising stuff_type 4

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

and

...
Initialising test_type
Initialising stuff_type 4
Finalising stuff_type 107478528
Copy initialiser 4 4
Initialising stuff_type 1
Finalising stuff_type 1
Copy initialiser 1 1
Initialising stuff_type 2
Finalising stuff_type 5120
Copy initialiser 2 2
Initialising stuff_type 3
Finalising stuff_type 0
Copy initialiser 3 3
Initialising stuff_type 4
Finalising stuff_type 1501114256
Copy initialiser 4 4
Finalising stuff_type 4
Copy initialiser 4 4
thing 14
Finalising stuff_type 4

where the nonzero values changed between different runs.

[Bug fortran/69298] Array finalisers seem to be given the wrong array when the array is a member variable.

2016-01-24 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69298

Dominique d'Humieres  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-01-24
 Blocks||37336
 Ever confirmed|0   |1

--- Comment #1 from Dominique d'Humieres  ---
I confirm a problem during the execution of the test:

thing 10
Finalising stuff_type 4

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

from 4.9 up to trunk (6.0), finalization being not implemented in 4.8.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=37336
[Bug 37336] [F03] Finish derived-type finalization

[Bug fortran/69298] Array finalisers seem to be given the wrong array when the array is a member variable.

2016-01-24 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69298

--- Comment #2 from Dominique d'Humieres  ---
Created attachment 37448
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37448=edit
Self-contained variant