From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1431) id B81B43857C68; Tue, 20 Apr 2021 06:31:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B81B43857C68 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Paul Thomas To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8255] Fortran: Fix host associated PDT entity initialization [PR99307]. X-Act-Checkin: gcc X-Git-Author: Paul Thomas X-Git-Refname: refs/heads/master X-Git-Oldrev: 30b11d8d1be9c683f1517472c47a3cb69df02c4f X-Git-Newrev: 67378cd63d62bf0c69e966d1d202a1e586550a68 Message-Id: <20210420063100.B81B43857C68@sourceware.org> Date: Tue, 20 Apr 2021 06:31:00 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Apr 2021 06:31:00 -0000 https://gcc.gnu.org/g:67378cd63d62bf0c69e966d1d202a1e586550a68 commit r11-8255-g67378cd63d62bf0c69e966d1d202a1e586550a68 Author: Paul Thomas Date: Tue Apr 20 07:30:07 2021 +0100 Fortran: Fix host associated PDT entity initialization [PR99307]. 2021-04-20 Paul Thomas 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. Diff: --- gcc/fortran/trans-decl.c | 3 ++- gcc/testsuite/gfortran.dg/pdt_26.f03 | 4 ++-- gcc/testsuite/gfortran.dg/pdt_31.f03 | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) 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 @@ -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" } } diff --git a/gcc/testsuite/gfortran.dg/pdt_31.f03 b/gcc/testsuite/gfortran.dg/pdt_31.f03 new file mode 100644 index 00000000000..708c9454217 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_31.f03 @@ -0,0 +1,26 @@ +! { dg-do run } +! +! Test the fix for PR100110, in which 'obj' was not being initialized. +! +! Contributed by Xiao Liu +! +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