re PR fortran/49885 (Segmentation fault when writing to an automatic character array)
authorDaniel Kraft <d@domob.eu>
Tue, 2 Aug 2011 20:10:13 +0000 (22:10 +0200)
committerDaniel Kraft <domob@gcc.gnu.org>
Tue, 2 Aug 2011 20:10:13 +0000 (22:10 +0200)
2011-08-02  Daniel Kraft  <d@domob.eu>

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  <d@domob.eu>

PR fortran/49885
* gfortran.dg/auto_char_dummy_array_3.f90: New test.

From-SVN: r177211

gcc/fortran/ChangeLog
gcc/fortran/trans-array.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/auto_char_dummy_array_3.f90 [new file with mode: 0644]

index bba8d0fb7705d35acbe65b94d5b4ec32d38876c0..912c011ba0a781bf38d0678641ba12b9b03944e9 100644 (file)
@@ -1,3 +1,9 @@
+2011-08-02  Daniel Kraft  <d@domob.eu>
+
+       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  <burnus@net-b.de>
 
        * trans-array.c (gfc_array_allocate): Pass token to
index a151c560bc1c78493fba587f7fd1c0723b53c056..85acf0cfbd033f9cb179362664610dae483c51fd 100644 (file)
@@ -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
index 7a4dc06365455604f47686590d7cc81d8503400f..82f2776ba464a681f9ffae2ce87276cc39d0f167 100644 (file)
@@ -1,3 +1,8 @@
+2011-08-02  Daniel Kraft  <d@domob.eu>
+
+       PR fortran/49885
+       * gfortran.dg/auto_char_dummy_array_3.f90: New test.
+
 2011-08-02  Kai Tietz  <ktietz@redhat.com>
 
        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 (file)
index 0000000..053956c
--- /dev/null
@@ -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 <d@domob.eu>,
+! 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