From 852f7e6f4aa2b27986de5a522cd6638f0f1a74e7 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Fri, 1 Dec 2017 07:35:50 +0000 Subject: [PATCH] re PR fortran/83224 (creating character array from elements shorter than declared does not pad with whitespace properly and aborts) 2017-12-01 Thomas Koenig PR fortran/83224 * frontend-passes.c (realloc_string_callback): Handle case for which the RHS is an array expression. 2017-12-01 Thomas Koenig PR fortran/83224 * gfortran.dg/dependency_50.f90: New test. From-SVN: r255294 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/frontend-passes.c | 7 ++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/dependency_50.f90 | 12 ++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/dependency_50.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index fc971583686..e6c048090ec 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-12-01 Thomas Koenig + + PR fortran/83224 + * frontend-passes.c (realloc_string_callback): Handle + case for which the RHS is an array expression. + 2017-11-28 Janne Blomqvist PR fortran/53796 diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index b3db18ac5f1..80d8767fc03 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -249,7 +249,7 @@ realloc_string_callback (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED, return 0; expr1 = co->expr1; - if (expr1->ts.type != BT_CHARACTER || expr1->rank != 0 + if (expr1->ts.type != BT_CHARACTER || !gfc_expr_attr(expr1).allocatable || !expr1->ts.deferred) return 0; @@ -270,8 +270,9 @@ realloc_string_callback (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED, if (!found_substr) return 0; } - else if (expr2->expr_type != EXPR_OP - || expr2->value.op.op != INTRINSIC_CONCAT) + else if (expr2->expr_type != EXPR_ARRAY + && (expr2->expr_type != EXPR_OP + || expr2->value.op.op != INTRINSIC_CONCAT)) return 0; if (!gfc_check_dependency (expr1, expr2, true)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 66ca1d2d315..f2a2f7e9e5f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-01 Thomas Koenig + + PR fortran/83224 + * gfortran.dg/dependency_50.f90: New test. + 2016-11-17 Kirill Yukhin * gcc.target/i386/avx512f-vpcompressb-2.c: Fix popcnt for 32-bit mode. diff --git a/gcc/testsuite/gfortran.dg/dependency_50.f90 b/gcc/testsuite/gfortran.dg/dependency_50.f90 new file mode 100644 index 00000000000..dfe0a3b9f5e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dependency_50.f90 @@ -0,0 +1,12 @@ +! { dg-do run } +! PR 83224 - dependency mishandling with an array constructor +! Original test case by Urban Jost +program dusty_corner + implicit none + character(len=:),allocatable :: words(:) + + words=[character(len=3) :: 'one', 'two'] + words=[character(len=5) :: words, 'three'] + if (any(words /= [ "one ", "two ", "three"])) call abort + +end program dusty_corner -- 2.30.2