From: Paul Thomas Date: Sun, 27 Jan 2019 18:53:47 +0000 (+0000) Subject: Backport PRs 56386, 58906, 77385, 80260, 82077 X-Git-Tag: releases/gcc-7.5.0~632 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7eb40d62a1a4ba93d6c3aa3ce6be913539242589;p=thirdparty%2Fgcc.git Backport PRs 56386, 58906, 77385, 80260, 82077 2019-01-27 Paul Thomas Backport from trunk PR fortran/56386 PR fortran/58906 PR fortran/77385 PR fortran/80260 PR fortran/82077 * resolve.c (resolve_variable): Fix up expressions with array associate names, where the parser did not detect that this is array and there was no array part_ref in the expression. * trans-expr.c (gfc_find_and_cut_at_last_class_ref): base_expr should be a copy of e and not the initialization expr. 2019-01-27 Paul Thomas Backport from trunk PR fortran/56386 PR fortran/58906 PR fortran/77385 * gfortran.dg/associate_44.f90 : New test. PR fortran/80260 * gfortran.dg/select_type_45.f90 : New test. PR fortran/82077 * gfortran.dg/select_type_46.f90 : New test. From-SVN: r268317 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 31610781d431..b012295a1be3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,17 @@ +2019-01-27 Paul Thomas + + Backport from trunk + PR fortran/56386 + PR fortran/58906 + PR fortran/77385 + PR fortran/80260 + PR fortran/82077 + * resolve.c (resolve_variable): Fix up expressions with array + associate names, where the parser did not detect that this is + array and there was no array part_ref in the expression. + * trans-expr.c (gfc_find_and_cut_at_last_class_ref): base_expr + should be a copy of e and not the initialization expr. + 2019-01-15 Steven G. Kargl PR fortran/81849 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 31808703d4d8..60f3ea9d592a 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5161,6 +5161,23 @@ resolve_variable (gfc_expr *e) gfc_fix_class_refs (e); if (!sym->attr.dimension && e->ref && e->ref->type == REF_ARRAY) return false; + else if (sym->attr.dimension && (!e->ref || e->ref->type != REF_ARRAY)) + { + /* This can happen because the parser did not detect that the + associate name is an array and the expression had no array + part_ref. */ + gfc_ref *ref = gfc_get_ref (); + ref->type = REF_ARRAY; + ref->u.ar = *gfc_get_array_ref(); + ref->u.ar.type = AR_FULL; + if (sym->as) + { + ref->u.ar.as = sym->as; + ref->u.ar.dimen = sym->as->rank; + } + ref->next = e->ref; + e->ref = ref; + } } if (sym->ts.type == BT_DERIVED && sym->ts.u.derived->attr.generic) diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 55cd3bb6c3f5..674eba9d9a6d 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -391,7 +391,7 @@ gfc_find_and_cut_at_last_class_ref (gfc_expr *e) e->ref = NULL; } - base_expr = gfc_expr_to_initialize (e); + base_expr = gfc_copy_expr (e); /* Restore the original tail expression. */ if (class_ref) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 910265293436..10f4c267c9fa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2019-01-27 Paul Thomas + + Backport from trunk + PR fortran/56386 + PR fortran/58906 + PR fortran/77385 + * gfortran.dg/associate_44.f90 : New test. + + PR fortran/80260 + * gfortran.dg/select_type_45.f90 : New test. + + PR fortran/82077 + * gfortran.dg/select_type_46.f90 : New test. + 2019-01-27 Eric Botcazou * gnat.dg/opt75.adb: New test. diff --git a/gcc/testsuite/gfortran.dg/associate_44.f90 b/gcc/testsuite/gfortran.dg/associate_44.f90 new file mode 100644 index 000000000000..de42d8aedd8a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/associate_44.f90 @@ -0,0 +1,23 @@ +! { dg-do compile } +! +! Test the fix for PR56386 +! +! Contributed by Vladimir Fuka +! +subroutine CustomSolidBodies + implicit none + + type inner + real :: elev + end type + + type :: outer + type(inner),dimension(0) :: PrPoints + end type + + type(outer) :: SB + + associate (Prter=>SB%PrPoints) + PrTer%elev=0 ! ICE here + end associate +end subroutine CustomSolidBodies diff --git a/gcc/testsuite/gfortran.dg/select_type_45.f90 b/gcc/testsuite/gfortran.dg/select_type_45.f90 new file mode 100644 index 000000000000..a5e04fabcad2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_type_45.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! +! Tests the fix for PR80260 +! +! Contributed by Damian Rouson +! + type foo + end type foo + type, extends(foo) :: bar + end type +contains + subroutine f(x) + class(foo) x(:,:) + select type(x) + class is (bar) + call g(x(1,:)) ! ICEd here. + end select + end subroutine + subroutine g(y) + class(bar) y(:) + end subroutine +end diff --git a/gcc/testsuite/gfortran.dg/select_type_46.f90 b/gcc/testsuite/gfortran.dg/select_type_46.f90 new file mode 100644 index 000000000000..7582ab78f911 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_type_46.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +! +! Tests the fix for PR82077 +! +! Contributed by Damian Rouson +! + type parent + end type parent + type, extends(parent) :: child + end type + class(parent), allocatable :: foo(:,:) + allocate(child::foo(1,1)) + select type(foo) + class is (child) + call gfortran7_ICE(foo(1,:)) ! ICEd here. + end select +contains + subroutine gfortran7_ICE(bar) + class(child) bar(:) + end subroutine +end