public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] PR 56691 - [OOP] Allocatable array: wrong offset when passing to CLASS dummy
@ 2018-01-27 12:41 Paul Richard Thomas
  2018-02-10 18:33 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Richard Thomas @ 2018-01-27 12:41 UTC (permalink / raw)
  To: fortran, gcc-patches, Dominique d'Humières

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

I am worried that this fix seems to easy by half and so I am posting
it for approval, rather than committing it as obvious. I would be
obliged if somebody would test it thoroughly.

Bootstraps and regtests on FC23/x86_64 - OK for trunk and 7 branch?

Paul

2018-27-01  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/56691
    * trans-array.c (gfc_conv_expr_descriptor): If the source array
    is a descriptor type, use its offset, removing the condition
    that is be a class expression.

2018-27-01  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/56691
    * gfortran.dg/type_to_class_4.f03: New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/plain, Size: 1902 bytes --]

Index: gcc/fortran/trans-array.c
===================================================================
*** gcc/fortran/trans-array.c	(revision 257065)
--- gcc/fortran/trans-array.c	(working copy)
*************** gfc_conv_expr_descriptor (gfc_se *se, gf
*** 7529,7537 ****
  	      : base;
  	  gfc_conv_descriptor_offset_set (&loop.pre, parm, tmp);
  	}
!       else if (IS_CLASS_ARRAY (expr) && !se->data_not_needed
! 	       && (!rank_remap || se->use_offset)
! 	       && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
  	{
  	  gfc_conv_descriptor_offset_set (&loop.pre, parm,
  					 gfc_conv_descriptor_offset_get (desc));
--- 7529,7537 ----
  	      : base;
  	  gfc_conv_descriptor_offset_set (&loop.pre, parm, tmp);
  	}
!       else if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc))
! 	       && !se->data_not_needed
! 	       && (!rank_remap || se->use_offset))
  	{
  	  gfc_conv_descriptor_offset_set (&loop.pre, parm,
  					 gfc_conv_descriptor_offset_get (desc));
Index: gcc/testsuite/gfortran.dg/type_to_class_4.f03
===================================================================
*** gcc/testsuite/gfortran.dg/type_to_class_4.f03	(nonexistent)
--- gcc/testsuite/gfortran.dg/type_to_class_4.f03	(working copy)
***************
*** 0 ****
--- 1,34 ----
+ ! { dg-do run }
+ !
+ ! Test the fix for PR56691 comment #7.
+ !
+ ! Contributed by Janus Weil  <janus@gcc.gnu.org>
+ !
+ module m2
+   implicit none
+   type :: t_stv
+     real :: f1
+   end type
+ contains
+   subroutine lcb(y)
+     class(t_stv), intent(in) :: y(:)
+     integer :: k
+     do k=1,size(y)
+       if (int(y(k)%f1) .ne. k) call abort
+     enddo
+   end subroutine
+ end module
+ 
+ program test
+  use m2
+  implicit none
+ 
+  type(t_stv), allocatable :: work(:)
+ 
+   allocate(work(4))
+   work(:)%f1 = (/ 1.,2.,3.,4./)
+ 
+   call lcb(work)
+   call lcb(work(:4)) ! Indexing used to be offset by 1.
+ 
+ end program

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

* Re: [Patch, fortran] PR 56691 - [OOP] Allocatable array: wrong offset when passing to CLASS dummy
  2018-01-27 12:41 [Patch, fortran] PR 56691 - [OOP] Allocatable array: wrong offset when passing to CLASS dummy Paul Richard Thomas
@ 2018-02-10 18:33 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2018-02-10 18:33 UTC (permalink / raw)
  To: fortran, gcc-patches, Dominique d'Humières

Hi All,

Committed as revision 257550. In the course of testing this patch,
Dominique found some problems that turned out to be due to revision
r257065. These latter were encapsulated in PR84155, which was fixed
257356. However, Richi pointed me in the direction of a much cleaner
fix to this PR and it seems that the failing tests that Dominique
found survive this patch :-)

Paul


2018-02-10  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/84141
PR fortran/84155
* trans-array.c (gfc_array_init_size): Revert the change made
in revision 257356 setting the dtype.
* trans-types.c (gfc_get_dtype): Do not use the cached dtype.
Call gfc_get_dtype_rank_type every time.

PR fortran/56691
* trans-array.c (gfc_conv_expr_descriptor): If the source array
is a descriptor type, use its offset, removing the condition
that is be a class expression.

2018-02-10  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/56691
* gfortran.dg/type_to_class_4.f03: New test.

On 27 January 2018 at 12:41, Paul Richard Thomas
<paul.richard.thomas@gmail.com> wrote:
> I am worried that this fix seems to easy by half and so I am posting
> it for approval, rather than committing it as obvious. I would be
> obliged if somebody would test it thoroughly.
>
> Bootstraps and regtests on FC23/x86_64 - OK for trunk and 7 branch?
>
> Paul
>
> 2018-27-01  Paul Thomas  <pault@gcc.gnu.org>
>
>     PR fortran/56691
>     * trans-array.c (gfc_conv_expr_descriptor): If the source array
>     is a descriptor type, use its offset, removing the condition
>     that is be a class expression.
>
> 2018-27-01  Paul Thomas  <pault@gcc.gnu.org>
>
>     PR fortran/56691
>     * gfortran.dg/type_to_class_4.f03: New test.



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

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

end of thread, other threads:[~2018-02-10 18:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-27 12:41 [Patch, fortran] PR 56691 - [OOP] Allocatable array: wrong offset when passing to CLASS dummy Paul Richard Thomas
2018-02-10 18:33 ` Paul Richard Thomas

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).