[gfortran,committed] Fix PR31974: mismatched types in multiplication
FX Coudert
fxcoudert@gmail.com
Sat May 19 19:58:00 GMT 2007
Hi all,
I committed the patch below after bootstrapping and regtesting on
x86_64-linux. It fixes PR31974, a 4.3 regression due to a bug exposed
by my recent malloc/free patch. The front-end generated mismatched
types in the calculation of the size of the memory to allocate.
FX
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-19 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/31974
* gfortran.dg/char_allocation_1.f90: New test.
Index: fortran/trans-array.c
===================================================================
--- fortran/trans-array.c (revision 124856)
+++ fortran/trans-array.c (working copy)
@@ -3846,7 +3846,8 @@ gfc_trans_auto_array_allocation (tree de
/* 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: testsuite/gfortran.dg/char_allocation_1.f90
===================================================================
--- testsuite/gfortran.dg/char_allocation_1.f90 (revision 0)
+++ testsuite/gfortran.dg/char_allocation_1.f90 (revision 0)
@@ -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
More information about the Fortran
mailing list