From f315a6b438a961737d5a0def08b4957866b348c7 Mon Sep 17 00:00:00 2001 From: Daniel Kraft Date: Tue, 2 Aug 2011 22:10:13 +0200 Subject: [PATCH] re PR fortran/49885 (Segmentation fault when writing to an automatic character array) 2011-08-02 Daniel Kraft PR fortran/49885 * trans-array.c (gfc_trans_auto_array_allocation): Change gfc_start_block to gfc_init_block to avoid spurious extra-scope. 2011-08-02 Daniel Kraft PR fortran/49885 * gfortran.dg/auto_char_dummy_array_3.f90: New test. From-SVN: r177211 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/trans-array.c | 2 +- gcc/testsuite/ChangeLog | 5 ++++ .../gfortran.dg/auto_char_dummy_array_3.f90 | 25 +++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/auto_char_dummy_array_3.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bba8d0fb770..912c011ba0a 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-08-02 Daniel Kraft + + PR fortran/49885 + * trans-array.c (gfc_trans_auto_array_allocation): Change + gfc_start_block to gfc_init_block to avoid spurious extra-scope. + 2011-08-02 Tobias Burnus * trans-array.c (gfc_array_allocate): Pass token to diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index a151c560bc1..85acf0cfbd0 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -4887,7 +4887,7 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * sym, gcc_assert (GFC_ARRAY_TYPE_P (type)); onstack = TREE_CODE (type) != POINTER_TYPE; - gfc_start_block (&init); + gfc_init_block (&init); /* Evaluate character string length. */ if (sym->ts.type == BT_CHARACTER diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7a4dc063654..82f2776ba46 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-08-02 Daniel Kraft + + PR fortran/49885 + * gfortran.dg/auto_char_dummy_array_3.f90: New test. + 2011-08-02 Kai Tietz PR middle-end/49947 diff --git a/gcc/testsuite/gfortran.dg/auto_char_dummy_array_3.f90 b/gcc/testsuite/gfortran.dg/auto_char_dummy_array_3.f90 new file mode 100644 index 00000000000..053956cabfd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/auto_char_dummy_array_3.f90 @@ -0,0 +1,25 @@ +! { dg-do run } + +! PR fortran/49885 +! Check that character arrays with non-constant char-length are handled +! correctly. + +! Contributed by Daniel Kraft , +! based on original test case and variant by Tobias Burnus in comment 2. + +PROGRAM main + IMPLICIT NONE + + CALL s (10) + +CONTAINS + + SUBROUTINE s (nb) + INTEGER :: nb + CHARACTER(MAX (80, nb)) :: bad_rec(1) + + bad_rec(1)(1:2) = 'abc' + IF (bad_rec(1)(1:2) /= 'ab') CALL abort () + END SUBROUTINE s + +END PROGRAM main -- 2.30.2