public inbox for gcc-patches@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>
Subject: [Patch, fortran] PR100110 - Parameterized Derived Types, problems with global variable
Date: Mon, 19 Apr 2021 13:40:19 +0100	[thread overview]
Message-ID: <CAGkQGi+Z1UfUYiYUQEqna5cbDg0H+DayKH=HS0-suEKyQX2qWQ@mail.gmail.com> (raw)

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

Hi All,

I was just about to announce that I will only do backports and regressions,
while I finally attack the fundamental problem with the representation of
Parameterized Derived Types. Then this PR came up that was such clear low
hanging fruit that I decided to fix it right away.

Regtests on FC33/x86_64 - OK for mainline?

Note that this is sufficiently safe that it could be applied to 11-branch
right now. However, I am prepared to hold off until 11-branch is released.

Regards

Paul

Fortran: Fix host associated PDT entity initialization [PR99307].

2021-04-19  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/100110
* trans-decl.c (gfc_get_symbol_decl): Replace test for host
association with a check that the current and symbol namespaces
are the same.

gcc/testsuite/
PR fortran/100110
* gfortran.dg/pdt_31.f03: New test.
* gfortran.dg/pdt_26.f03: Reduce 'builtin_malloc' count from 9
to 8.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 1575 bytes --]

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 34a0d49bae7..cc9d85543ca 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1548,7 +1548,8 @@ gfc_get_symbol_decl (gfc_symbol * sym)
      declaration of the entity and memory allocated/deallocated.  */
   if ((sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS)
       && sym->param_list != NULL
-      && !(sym->attr.host_assoc || sym->attr.use_assoc || sym->attr.dummy))
+      && gfc_current_ns == sym->ns
+      && !(sym->attr.use_assoc || sym->attr.dummy))
     gfc_defer_symbol_init (sym);
 
   /* Dummy PDT 'len' parameters should be checked when they are explicit.  */
diff --git a/gcc/testsuite/gfortran.dg/pdt_26.f03 b/gcc/testsuite/gfortran.dg/pdt_26.f03
index bf1273743d3..59ddcfb6cc4 100644
--- a/gcc/testsuite/gfortran.dg/pdt_26.f03
+++ b/gcc/testsuite/gfortran.dg/pdt_26.f03
@@ -2,7 +2,7 @@
 ! { dg-options "-fdump-tree-original" }
 !
 ! Test the fix for PR83567 in which the parameterized component 'foo' was
-! being deallocated before return from 'addw', with consequent segfault in 
+! being deallocated before return from 'addw', with consequent segfault in
 ! the main program.
 !
 ! Contributed by Berke Durak  <berke.durak@gmail.com>
@@ -43,4 +43,4 @@ program test_pdt
   if (any (c(1)%foo .ne. [13,15,17])) STOP 2
 end program test_pdt
 ! { dg-final { scan-tree-dump-times "__builtin_free" 8 "original" } }
-! { dg-final { scan-tree-dump-times "__builtin_malloc" 9 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_malloc" 8 "original" } }

[-- Attachment #3: pdt_31.f03 --]
[-- Type: application/octet-stream, Size: 586 bytes --]

! { dg-do run }
!
! Test the fix for PR100110, in which 'obj' was not being initialized.
!
! Contributed by Xiao Liu  <xiao.liu@compiler-dev.com>
!
program p
  implicit none
  type t(n)
    integer, len :: n
    integer :: arr(n, n)
  end type

  type(t(2)) :: obj

  obj%arr = reshape ([1,2,3,4],[2,2])
  if (obj%n .ne. 2) stop 1
  if (any (shape(obj%arr) .ne. [2,2])) stop 2
  call test()
contains
  subroutine test()
    if (obj%n .ne. 2) stop 3
    if (any (shape(obj%arr) .ne. [2,2])) stop 4
    if (any (reshape (obj%arr, [4]) .ne. [1,2,3,4])) stop 5
  end subroutine
end program

             reply	other threads:[~2021-04-19 12:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 12:40 Paul Richard Thomas [this message]
2021-04-19 13:08 ` Tobias Burnus
2021-04-20  8:55   ` Paul Richard Thomas
2021-04-20  9:58     ` Tobias Burnus
2021-04-20 10:02       ` Jakub Jelinek
2021-04-20 10:07       ` Tobias Burnus
2021-04-20 10:51         ` 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='CAGkQGi+Z1UfUYiYUQEqna5cbDg0H+DayKH=HS0-suEKyQX2qWQ@mail.gmail.com' \
    --to=paul.richard.thomas@gmail.com \
    --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).