public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	"Dominique d'Humières" <dominiq@tournesol.lps.ens.fr>
Subject: [Patch, fortran] PR 56691 - [OOP] Allocatable array: wrong offset when passing to CLASS dummy
Date: Sat, 27 Jan 2018 12:41:00 -0000	[thread overview]
Message-ID: <CAGkQGiJzNYw2QFKvGYj76VjdiLPDk2zmrZQ2Bwi5DgXDaD5Tqw@mail.gmail.com> (raw)

[-- 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

             reply	other threads:[~2018-01-27 12:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-27 12:41 Paul Richard Thomas [this message]
2018-02-10 18:33 ` Paul Richard Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGkQGiJzNYw2QFKvGYj76VjdiLPDk2zmrZQ2Bwi5DgXDaD5Tqw@mail.gmail.com \
    --to=paul.richard.thomas@gmail.com \
    --cc=dominiq@tournesol.lps.ens.fr \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).