re PR fortran/31974 ([4.2]: array allocation multiplication of mismatched types)
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sat, 19 May 2007 19:51:21 +0000 (19:51 +0000)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Sat, 19 May 2007 19:51:21 +0000 (19:51 +0000)
PR fortran/31974

* trans-array.c (gfc_trans_auto_array_allocation): Avoid
multiplication of mismatched types.

* gfortran.dg/char_allocation_1.f90: New test.

From-SVN: r124858

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

index 08c9d33a0d13cfef26b1e3f341b93567df4ffba2..2c9820b7f7183395af193aada4b1f5eaf43b8c5b 100644 (file)
@@ -1,3 +1,9 @@
+2007-05-19  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR fortran/31974
+       * trans-array.c (gfc_trans_auto_array_allocation): Avoid
+       multiplication of mismatched types.
+
 2007-05-18  Daniel Franke  <franke.daniel@gmail.com>
 
        PR fortran/24633
index 61e35543fe315971ca7c362b7cf948f82dd51f86..dfbdef0b5940e834e0f56ceda24bfe00ab190f57 100644 (file)
@@ -3846,7 +3846,8 @@ gfc_trans_auto_array_allocation (tree decl, gfc_symbol * sym, tree fnbody)
   /* The size is the number of elements in the array, so multiply by the
      size of an element to get the total size.  */
   tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
-  size = fold_build2 (MULT_EXPR, gfc_array_index_type, size, tmp);
+  size = fold_build2 (MULT_EXPR, gfc_array_index_type, size,
+                     fold_convert (gfc_array_index_type, tmp));
 
   /* Allocate memory to hold the data.  */
   tmp = gfc_call_malloc (&block, TREE_TYPE (decl), size);
index 56565874039329b9b049fffdff3e8b31048c1086..787e256a4101c9a83fac322648994b2307489d19 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-19  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       PR fortran/31974
+       * gfortran.dg/char_allocation_1.f90: New test.
+
 2007-05-19  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        * gcc.dg/Wconversion-integer.c: Group testcases and add more.
diff --git a/gcc/testsuite/gfortran.dg/char_allocation_1.f90 b/gcc/testsuite/gfortran.dg/char_allocation_1.f90
new file mode 100644 (file)
index 0000000..119badb
--- /dev/null
@@ -0,0 +1,11 @@
+! PR fortran/31974
+! { dg-do run }
+  subroutine foo (n)
+    integer :: n
+    character (len = n) :: v(n)
+    v = ''
+    if (any (v /= '')) call abort
+  end subroutine foo
+
+  call foo(7)
+  end