From c2d42d16195d87ad6fb063a0db0287ad197a972b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 16 Dec 2016 20:41:13 +0100 Subject: [PATCH] re PR fortran/78757 (ICE with function returning a pointer to a character) PR fortran/78757 * trans-expr.c (gfc_conv_procedure_call): Emit DECL_EXPR for the type pstr var points to. * gfortran.dg/char_result_16.f90: New test. From-SVN: r243761 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-expr.c | 13 +++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/char_result_16.f90 | 16 ++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/char_result_16.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7f66ed5f5ab..e4605048b17 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-12-16 Jakub Jelinek + + PR fortran/78757 + * trans-expr.c (gfc_conv_procedure_call): Emit DECL_EXPR for the + type pstr var points to. + 2016-12-15 Janus Weil PR fortran/78798 diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index f908c25b9cb..823c96aa4cd 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -6009,6 +6009,19 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, { var = gfc_create_var (type, "pstr"); + /* Emit a DECL_EXPR for the VLA type. */ + tmp = TREE_TYPE (type); + if (TYPE_SIZE (tmp) + && TREE_CODE (TYPE_SIZE (tmp)) != INTEGER_CST) + { + tmp = build_decl (input_location, TYPE_DECL, NULL_TREE, tmp); + DECL_ARTIFICIAL (tmp) = 1; + DECL_IGNORED_P (tmp) = 1; + tmp = fold_build1_loc (input_location, DECL_EXPR, + TREE_TYPE (tmp), tmp); + gfc_add_expr_to_block (&se->pre, tmp); + } + if ((!comp && sym->attr.allocatable) || (comp && comp->attr.allocatable)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 30f89311da8..c0b849324d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-12-16 Jakub Jelinek + + PR fortran/78757 + * gfortran.dg/char_result_16.f90: New test. + 2016-12-16 Kyrylo Tkachov * gcc.target/aarch64/ubfiz_lsl_1.c: New test. diff --git a/gcc/testsuite/gfortran.dg/char_result_16.f90 b/gcc/testsuite/gfortran.dg/char_result_16.f90 new file mode 100644 index 00000000000..adb86d5090c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_result_16.f90 @@ -0,0 +1,16 @@ +! PR fortran/78757 +! { dg-do compile } +! { dg-options "-O1" } + +program pr78757 + implicit none + character (len = 30), target :: x + character (len = 30), pointer :: s + s => foo (30_8) +contains + function foo (i) + integer (8) :: i + character (len = i), pointer :: foo + foo => x + end function foo +end program pr78757 -- 2.30.2