[Patch, fortran] PR58410 - [4.8/4.9 Regression] Bogus uninitialized variable warning for allocatable derived type array function result
Paul Richard Thomas
paul.richard.thomas@gmail.com
Sat Nov 30 20:13:00 GMT 2013
Dear All,
This turned out to be a valid uninitialized variable warning.
However, it was unlikely ever to cause problems at run-time.
Nonetheless, here is the fix. I am disinclined to load the testsuite
with a fix that is so specific and localized that it simply will not
break. However, if reviewers think otherwise, I can easily add the
original testcase.
Bootstrapped and regtested on FC17/x86_64 - OK from trunk and 4.8?
Cheers
Paul
2013-11-30 Paul Thomas <pault@gcc.gnu.org>
PR fortran/58410
* trans-array.c (gfc_alloc_allocatable_for_assignment): Do not
use the array bounds of an unallocated array but set its size
to zero instead.
-------------- next part --------------
Index: gcc/fortran/trans-array.c
===================================================================
*** gcc/fortran/trans-array.c (revision 205031)
--- gcc/fortran/trans-array.c (working copy)
*************** gfc_alloc_allocatable_for_assignment (gf
*** 8068,8073 ****
--- 8076,8082 ----
tree size1;
tree size2;
tree array1;
+ tree cond_null;
tree cond;
tree tmp;
tree tmp2;
*************** gfc_alloc_allocatable_for_assignment (gf
*** 8143,8151 ****
jump_label2 = gfc_build_label_decl (NULL_TREE);
/* Allocate if data is NULL. */
! cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
array1, build_int_cst (TREE_TYPE (array1), 0));
! tmp = build3_v (COND_EXPR, cond,
build1_v (GOTO_EXPR, jump_label1),
build_empty_stmt (input_location));
gfc_add_expr_to_block (&fblock, tmp);
--- 8152,8160 ----
jump_label2 = gfc_build_label_decl (NULL_TREE);
/* Allocate if data is NULL. */
! cond_null = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node,
array1, build_int_cst (TREE_TYPE (array1), 0));
! tmp = build3_v (COND_EXPR, cond_null,
build1_v (GOTO_EXPR, jump_label1),
build_empty_stmt (input_location));
gfc_add_expr_to_block (&fblock, tmp);
*************** gfc_alloc_allocatable_for_assignment (gf
*** 8197,8209 ****
tmp = build1_v (LABEL_EXPR, jump_label1);
gfc_add_expr_to_block (&fblock, tmp);
! size1 = gfc_conv_descriptor_size (desc, expr1->rank);
! /* Get the rhs size. Fix both sizes. */
if (expr2)
desc2 = rss->info->data.array.descriptor;
else
desc2 = NULL_TREE;
size2 = gfc_index_one_node;
for (n = 0; n < expr2->rank; n++)
{
--- 8206,8230 ----
tmp = build1_v (LABEL_EXPR, jump_label1);
gfc_add_expr_to_block (&fblock, tmp);
! /* If the lhs has not been allocated, its bounds will not have been
! initialized and so its size is set to zero. */
! size1 = gfc_create_var (gfc_array_index_type, NULL);
! gfc_init_block (&alloc_block);
! gfc_add_modify (&alloc_block, size1, gfc_index_zero_node);
! gfc_init_block (&realloc_block);
! gfc_add_modify (&realloc_block, size1,
! gfc_conv_descriptor_size (desc, expr1->rank));
! tmp = build3_v (COND_EXPR, cond_null,
! gfc_finish_block (&alloc_block),
! gfc_finish_block (&realloc_block));
! gfc_add_expr_to_block (&fblock, tmp);
! /* Get the rhs size and fix it. */
if (expr2)
desc2 = rss->info->data.array.descriptor;
else
desc2 = NULL_TREE;
+
size2 = gfc_index_one_node;
for (n = 0; n < expr2->rank; n++)
{
*************** gfc_alloc_allocatable_for_assignment (gf
*** 8217,8224 ****
gfc_array_index_type,
tmp, size2);
}
-
- size1 = gfc_evaluate_now (size1, &fblock);
size2 = gfc_evaluate_now (size2, &fblock);
cond = fold_build2_loc (input_location, NE_EXPR, boolean_type_node,
--- 8238,8243 ----
More information about the Fortran
mailing list