From 61f70bf208644b9b2f3b76ba9c324eb7c4a4cfa1 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Sat, 19 May 2007 19:51:21 +0000 Subject: [PATCH] re PR fortran/31974 ([4.2]: array allocation multiplication of mismatched types) 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 | 6 ++++++ gcc/fortran/trans-array.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/char_allocation_1.f90 | 11 +++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/char_allocation_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 08c9d33a0d1..2c9820b7f71 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2007-05-19 Francois-Xavier Coudert + + PR fortran/31974 + * trans-array.c (gfc_trans_auto_array_allocation): Avoid + multiplication of mismatched types. + 2007-05-18 Daniel Franke PR fortran/24633 diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 61e35543fe3..dfbdef0b594 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 56565874039..787e256a410 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-05-19 Francois-Xavier Coudert + + PR fortran/31974 + * gfortran.dg/char_allocation_1.f90: New test. + 2007-05-19 Manuel Lopez-Ibanez * 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 index 00000000000..119badb4d10 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/char_allocation_1.f90 @@ -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 -- 2.30.2