From: Paul Thomas Date: Sat, 21 Dec 2019 18:21:21 +0000 (+0000) Subject: re PR fortran/92753 (ICE in gfc_trans_call, at fortran/trans-stmt.c:392) X-Git-Tag: releases/gcc-9.3.0~276 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c7b124504f6045f19fce1a55bd4cd1e94022fdb;p=thirdparty%2Fgcc.git re PR fortran/92753 (ICE in gfc_trans_call, at fortran/trans-stmt.c:392) 2019-12-21  Paul Thomas   PR fortran/92753 * expr.c (find_inquiry_ref): Catch INQUIRY_LEN case, where the temporary expression has been converted to a constant and make the new expression accordingly. Correct the error in INQUIRY_RE and INQUIRY_IM cases. The original rather than the resolved expression was being used as the source in mpfr_set. 2019-12-21  Paul Thomas   PR fortran/92753 * gfortran.dg/inquiry_type_ref_5.f90 : New test. From-SVN: r279697 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 41afcfdd12dc..834f172c2e95 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,13 @@ +2019-12-21  Paul Thomas   + + Backported from mainline + PR fortran/92753 + * expr.c (find_inquiry_ref): Catch INQUIRY_LEN case, where the + temporary expression has been converted to a constant and make + the new expression accordingly. Correct the error in INQUIRY_RE + and INQUIRY_IM cases. The original rather than the resolved + expression was being used as the source in mpfr_set. + 2019-12-20 Jakub Jelinek Backported from mainline diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index cad0dd36a671..5663d91fe0ff 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1780,11 +1780,15 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp) if (!gfc_notify_std (GFC_STD_F2003, "LEN part_ref at %C")) goto cleanup; - if (!tmp->ts.u.cl->length - || tmp->ts.u.cl->length->expr_type != EXPR_CONSTANT) + if (tmp->ts.u.cl->length + && tmp->ts.u.cl->length->expr_type == EXPR_CONSTANT) + *newp = gfc_copy_expr (tmp->ts.u.cl->length); + else if (tmp->expr_type == EXPR_CONSTANT) + *newp = gfc_get_int_expr (gfc_default_integer_kind, + NULL, tmp->value.character.length); + else goto cleanup; - *newp = gfc_copy_expr (tmp->ts.u.cl->length); break; case INQUIRY_KIND: @@ -1807,7 +1811,7 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp) *newp = gfc_get_constant_expr (BT_REAL, tmp->ts.kind, &tmp->where); mpfr_set ((*newp)->value.real, - mpc_realref (p->value.complex), GFC_RND_MODE); + mpc_realref (tmp->value.complex), GFC_RND_MODE); break; case INQUIRY_IM: @@ -1819,7 +1823,7 @@ find_inquiry_ref (gfc_expr *p, gfc_expr **newp) *newp = gfc_get_constant_expr (BT_REAL, tmp->ts.kind, &tmp->where); mpfr_set ((*newp)->value.real, - mpc_imagref (p->value.complex), GFC_RND_MODE); + mpc_imagref (tmp->value.complex), GFC_RND_MODE); break; } tmp = gfc_copy_expr (*newp); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3f08a3b80120..d2177c79e4d9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-12-21  Paul Thomas   + + Backported from mainline + PR fortran/92753 + * gfortran.dg/inquiry_type_ref_5.f90 : New test. + 2019-12-20 Jakub Jelinek Backported from mainline diff --git a/gcc/testsuite/gfortran.dg/inquiry_type_ref_5.f90 b/gcc/testsuite/gfortran.dg/inquiry_type_ref_5.f90 new file mode 100644 index 000000000000..b27943ae496f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/inquiry_type_ref_5.f90 @@ -0,0 +1,29 @@ +! { dg-do run } +! +! Test the fix for pr92753 +! +! Contributed by Gerhardt Steinmetz +! +module m + type t + character(3) :: c + end type + type u + complex :: z + end type + type(t), parameter :: x = t ('abc') + integer, parameter :: l = x%c%len ! Used to ICE + + type(u), parameter :: z = u ((42.0,-42.0)) +end +program p + use m + call s (x%c%len) ! ditto + + if (int (z%z%re) .ne. 42) stop 1 ! Produced wrong code and + if (int (z%z%re) .ne. -int (z%z%im)) stop 2 ! runtime seg fault +contains + subroutine s(n) + if (n .ne. l) stop 3 + end +end