diff options
| author | Francois-Xavier Coudert <coudert@clipper.ens.fr> | 2007-02-09 21:31:18 +0100 |
|---|---|---|
| committer | François-Xavier Coudert <fxcoudert@gcc.gnu.org> | 2007-02-09 20:31:18 +0000 |
| commit | 999ffb1a4b306ac65f47444ba5e2e63fb897c6c1 (patch) | |
| tree | 8d0107920863d9845a91d346a3352bc386b12cc7 /gcc/fortran/trans-array.c | |
| parent | b964502b99b17301bd22fb9932a97c55ebf8b945 (diff) | |
| download | gcc-999ffb1a4b306ac65f47444ba5e2e63fb897c6c1.zip gcc-999ffb1a4b306ac65f47444ba5e2e63fb897c6c1.tar.gz gcc-999ffb1a4b306ac65f47444ba5e2e63fb897c6c1.tar.bz2 | |
re PR fortran/30720 ([4.1 only] runtime: check for empty array slices before allocating a negative amount of memory)
PR fortran/30720
* trans-array.c (gfc_trans_create_temp_array): Remove use of the
function argument. Always generate code for negative extent.
Simplify said code.
* trans-array.h (gfc_trans_create_temp_array): Change prototype.
* trans-expr.c (gfc_conv_function_call): Remove use of last argument
of gfc_trans_create_temp_array.
* trans-intrinsic.c (gfc_conv_intrinsic_array_transfer): Likewise.
* trans-stmt.c (gfc_conv_elemental_dependencies): Likewise.
* gfortran.dg/array_function_1.f90: New test.
From-SVN: r121773
Diffstat (limited to 'gcc/fortran/trans-array.c')
| -rw-r--r-- | gcc/fortran/trans-array.c | 59 |
1 files changed, 14 insertions, 45 deletions
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index a39f6647..1c89975 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -583,7 +583,7 @@ tree gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, gfc_loopinfo * loop, gfc_ss_info * info, tree eltype, bool dynamic, bool dealloc, - bool callee_alloc, bool function) + bool callee_alloc) { tree type; tree desc; @@ -592,11 +592,6 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, tree nelem; tree cond; tree or_expr; - tree thencase; - tree elsecase; - tree var; - stmtblock_t thenblock; - stmtblock_t elseblock; int n; int dim; @@ -678,19 +673,16 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, tmp = fold_build2 (PLUS_EXPR, gfc_array_index_type, loop->to[n], gfc_index_one_node); - if (function) - { - /* Check whether the size for this dimension is negative. */ - cond = fold_build2 (LE_EXPR, boolean_type_node, tmp, + /* Check whether the size for this dimension is negative. */ + cond = fold_build2 (LE_EXPR, boolean_type_node, tmp, gfc_index_zero_node); + cond = gfc_evaluate_now (cond, pre); - cond = gfc_evaluate_now (cond, pre); + if (n == 0) + or_expr = cond; + else + or_expr = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, or_expr, cond); - if (n == 0) - or_expr = cond; - else - or_expr = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, or_expr, cond); - } size = fold_build2 (MULT_EXPR, gfc_array_index_type, size, tmp); size = gfc_evaluate_now (size, pre); } @@ -699,33 +691,10 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post, if (size && !callee_alloc) { - if (function) - { - /* If we know at compile-time whether any dimension size is - negative, we can avoid a conditional and pass the true size - to gfc_trans_allocate_array_storage, which can then decide - whether to allocate this on the heap or on the stack. */ - if (integer_zerop (or_expr)) - ; - else if (integer_onep (or_expr)) - size = gfc_index_zero_node; - else - { - var = gfc_create_var (TREE_TYPE (size), "size"); - gfc_start_block (&thenblock); - gfc_add_modify_expr (&thenblock, var, gfc_index_zero_node); - thencase = gfc_finish_block (&thenblock); - - gfc_start_block (&elseblock); - gfc_add_modify_expr (&elseblock, var, size); - elsecase = gfc_finish_block (&elseblock); - - tmp = gfc_evaluate_now (or_expr, pre); - tmp = build3_v (COND_EXPR, tmp, thencase, elsecase); - gfc_add_expr_to_block (pre, tmp); - size = var; - } - } + /* If or_expr is true, then the extent in at least one + dimension is zero and the size is set to zero. */ + size = fold_build3 (COND_EXPR, gfc_array_index_type, + or_expr, gfc_index_zero_node, size); nelem = size; size = fold_build2 (MULT_EXPR, gfc_array_index_type, size, @@ -1647,7 +1616,7 @@ gfc_trans_array_constructor (gfc_loopinfo * loop, gfc_ss * ss) } gfc_trans_create_temp_array (&loop->pre, &loop->post, loop, &ss->data.info, - type, dynamic, true, false, false); + type, dynamic, true, false); desc = ss->data.info.descriptor; offset = gfc_index_zero_node; @@ -3241,7 +3210,7 @@ gfc_conv_loop_setup (gfc_loopinfo * loop) loop->temp_ss->data.info.dimen = n; gfc_trans_create_temp_array (&loop->pre, &loop->post, loop, &loop->temp_ss->data.info, tmp, false, true, - false, false); + false); } for (n = 0; n < loop->temp_dim; n++) |
