From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1534) id 1C25F3858430; Mon, 7 Mar 2022 21:12:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C25F3858430 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tobias Burnus To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7526] Fortran: Fix gfc_maybe_dereference_var [PR104430][PR99585] X-Act-Checkin: gcc X-Git-Author: Tobias Burnus X-Git-Refname: refs/heads/master X-Git-Oldrev: 0af37ad4422052be4b7f779737e14c80e57d0ad9 X-Git-Newrev: c0134b7383992aab5c1a91440dbdd8fbb747169c Message-Id: <20220307211256.1C25F3858430@sourceware.org> Date: Mon, 7 Mar 2022 21:12:56 +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: Mon, 07 Mar 2022 21:12:56 -0000 https://gcc.gnu.org/g:c0134b7383992aab5c1a91440dbdd8fbb747169c commit r12-7526-gc0134b7383992aab5c1a91440dbdd8fbb747169c Author: Tobias Burnus Date: Mon Mar 7 22:11:33 2022 +0100 Fortran: Fix gfc_maybe_dereference_var [PR104430][PR99585] PR fortran/99585 PR fortran/104430 gcc/fortran/ChangeLog: * trans-expr.cc (conv_parent_component_references): Fix comment; simplify comparison. (gfc_maybe_dereference_var): Avoid d referencing a nonpointer. gcc/testsuite/ChangeLog: * gfortran.dg/class_result_10.f90: New test. Diff: --- gcc/fortran/trans-expr.cc | 6 ++-- gcc/testsuite/gfortran.dg/class_result_10.f90 | 52 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index c9d9a916c28..71d037101d4 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -2805,9 +2805,9 @@ conv_parent_component_references (gfc_se * se, gfc_ref * ref) dt = ref->u.c.sym; c = ref->u.c.component; - /* Return if the component is in the parent type. */ + /* Return if the component is in this type, i.e. not in the parent type. */ for (cmp = dt->components; cmp; cmp = cmp->next) - if (strcmp (c->name, cmp->name) == 0) + if (c == cmp) return; /* Build a gfc_ref to recursively call gfc_conv_component_ref. */ @@ -2867,6 +2867,8 @@ tree gfc_maybe_dereference_var (gfc_symbol *sym, tree var, bool descriptor_only_p, bool is_classarray) { + if (!POINTER_TYPE_P (TREE_TYPE (var))) + return var; if (is_CFI_desc (sym, NULL)) return build_fold_indirect_ref_loc (input_location, var); diff --git a/gcc/testsuite/gfortran.dg/class_result_10.f90 b/gcc/testsuite/gfortran.dg/class_result_10.f90 new file mode 100644 index 00000000000..a4d29ab9c1d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/class_result_10.f90 @@ -0,0 +1,52 @@ +! { dg-do run} + + +! PR fortran/99585 + +module m2 + type t + class(*), pointer :: bar(:) + end type + type t2 + class(t), allocatable :: my(:) + end type t2 +contains + function f (x, y) result(z) + class(t) :: x(:) + class(t) :: y(size(x(1)%bar)) + type(t) :: z(size(x(1)%bar)) + end + function g (x) result(z) + class(t) :: x(:) + type(t) :: z(size(x(1)%bar)) + end + subroutine s () + class(t2), allocatable :: a(:), b(:), c(:), d(:) + class(t2), pointer :: p(:) + c(1)%my = f (a(1)%my, b(1)%my) + d(1)%my = g (p(1)%my) + end +end + +! Contributed by G. Steinmetz: +! PR fortran/104430 + +module m + type t + integer :: a + end type +contains + function f(x) result(z) + class(t) :: x(:) + type(t) :: z(size(x%a)) + z%a = 42 + end +end +program p + use m + class(t), allocatable :: y(:), z(:) + allocate (y(32)) + z = f(y) + if (size(z) /= 32) stop 1 + if (any (z%a /= 42)) stop 2 +end