aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Vehreschild <vehre@gcc.gnu.org>2017-02-05 13:42:31 +0100
committerAndre Vehreschild <vehre@gcc.gnu.org>2017-02-05 13:42:31 +0100
commit764d5c7b5376677bd6e592fa969065f58dc3d816 (patch)
treeed731d55c2fb0281f28245a8d9e7f4d23be3ab70
parent4b9c80d8e4a1d14f6e517aac2267675910488510 (diff)
downloadgcc-764d5c7b5376677bd6e592fa969065f58dc3d816.zip
gcc-764d5c7b5376677bd6e592fa969065f58dc3d816.tar.gz
gcc-764d5c7b5376677bd6e592fa969065f58dc3d816.tar.bz2
re PR fortran/78958 (Unallocated memory access after SOURCE-ALLOCATEing unlimited polymorphic object)
gcc/fortran/ChangeLog: 2017-02-05 Andre Vehreschild <vehre@gcc.gnu.org> PR fortran/78958 * trans-stmt.c (gfc_trans_allocate): Add the multiplying the _len component of unlimited polymorphic objects when source-allocating. From-SVN: r245192
-rw-r--r--gcc/fortran/ChangeLog6
-rw-r--r--gcc/fortran/trans-stmt.c23
2 files changed, 21 insertions, 8 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 63af2ae..601017d 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,11 @@
2017-02-05 Andre Vehreschild <vehre@gcc.gnu.org>
+ PR fortran/78958
+ * trans-stmt.c (gfc_trans_allocate): Add the multiplying the _len
+ component of unlimited polymorphic objects when source-allocating.
+
+2017-02-05 Andre Vehreschild <vehre@gcc.gnu.org>
+
PR fortran/79230
* trans-array.c (structure_alloc_comps): Ignore pointer components when
freeing structures.
diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index ad4b737..61e597f 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -6009,14 +6009,21 @@ gfc_trans_allocate (gfc_code * code)
needs to be provided, which is done most of the time by the
pre-evaluation step. */
nelems = NULL_TREE;
- if (expr3_len && code->expr3->ts.type == BT_CHARACTER)
- /* When al is an array, then the element size for each element
- in the array is needed, which is the product of the len and
- esize for char arrays. */
- tmp = fold_build2_loc (input_location, MULT_EXPR,
- TREE_TYPE (expr3_esize), expr3_esize,
- fold_convert (TREE_TYPE (expr3_esize),
- expr3_len));
+ if (expr3_len && (code->expr3->ts.type == BT_CHARACTER
+ || code->expr3->ts.type == BT_CLASS))
+ {
+ /* When al is an array, then the element size for each element
+ in the array is needed, which is the product of the len and
+ esize for char arrays. For unlimited polymorphics len can be
+ zero, therefore take the maximum of len and one. */
+ tmp = fold_build2_loc (input_location, MAX_EXPR,
+ TREE_TYPE (expr3_len),
+ expr3_len, fold_convert (TREE_TYPE (expr3_len),
+ integer_one_node));
+ tmp = fold_build2_loc (input_location, MULT_EXPR,
+ TREE_TYPE (expr3_esize), expr3_esize,
+ fold_convert (TREE_TYPE (expr3_esize), tmp));
+ }
else
tmp = expr3_esize;
if (!gfc_array_allocate (&se, expr, stat, errmsg, errlen,