Commit 79cae72e by Jakub Jelinek Committed by Jakub Jelinek

re PR fortran/46945 (gfortran.dg/unpack_zerosize_1.f90 FAILs with -ftree-vrp…

re PR fortran/46945 (gfortran.dg/unpack_zerosize_1.f90 FAILs with -ftree-vrp -fno-tree-ccp -fno-tree-fre)

	PR fortran/46945
	* trans-array.c (gfc_array_init_size): Perform stride overflow
	checking and multiplication by element_size in size_type_node instead
	of sizetype, return value with size_type_node type instead of
	sometimes with sizetype and sometimes with gfc_array_index_type.

	* gfortran.dg/pr46945.f90: New test.

From-SVN: r167871
parent 50ba28bb
2010-12-15 Jakub Jelinek <jakub@redhat.com>
PR fortran/46945
* trans-array.c (gfc_array_init_size): Perform stride overflow
checking and multiplication by element_size in size_type_node instead
of sizetype, return value with size_type_node type instead of
sometimes with sizetype and sometimes with gfc_array_index_type.
2010-12-15 Janne Blomqvist <jb@gcc.gnu.org> 2010-12-15 Janne Blomqvist <jb@gcc.gnu.org>
* trans.c (gfc_allocate_with_status): Better error message for * trans.c (gfc_allocate_with_status): Better error message for
......
...@@ -4006,6 +4006,7 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset, ...@@ -4006,6 +4006,7 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
tree or_expr; tree or_expr;
tree thencase; tree thencase;
tree elsecase; tree elsecase;
tree cond;
tree var; tree var;
stmtblock_t thenblock; stmtblock_t thenblock;
stmtblock_t elseblock; stmtblock_t elseblock;
...@@ -4091,17 +4092,15 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset, ...@@ -4091,17 +4092,15 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
fold_convert (gfc_array_index_type, fold_convert (gfc_array_index_type,
TYPE_MAX_VALUE (gfc_array_index_type)), TYPE_MAX_VALUE (gfc_array_index_type)),
size); size);
tmp = fold_build3_loc cond = gfc_unlikely (fold_build2_loc (input_location, LT_EXPR,
(input_location, COND_EXPR, integer_type_node, boolean_type_node, tmp, stride));
gfc_unlikely (fold_build2_loc (input_location, LT_EXPR, tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond,
boolean_type_node, tmp, stride)), integer_one_node, integer_zero_node);
integer_one_node, integer_zero_node); cond = gfc_unlikely (fold_build2_loc (input_location, EQ_EXPR,
tmp = fold_build3_loc boolean_type_node, size,
(input_location, COND_EXPR, integer_type_node, gfc_index_zero_node));
gfc_unlikely (fold_build2_loc (input_location, EQ_EXPR, tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond,
boolean_type_node, size, integer_zero_node, tmp);
build_zero_cst (gfc_array_index_type))),
integer_zero_node, tmp);
tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node, tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
*overflow, tmp); *overflow, tmp);
*overflow = gfc_evaluate_now (tmp, pblock); *overflow = gfc_evaluate_now (tmp, pblock);
...@@ -4154,31 +4153,29 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset, ...@@ -4154,31 +4153,29 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
size of an element to get the total size. */ size of an element to get the total size. */
tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type)); tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type));
/* Convert to size_t. */ /* Convert to size_t. */
element_size = fold_convert (sizetype, tmp); element_size = fold_convert (size_type_node, tmp);
stride = fold_convert (sizetype, stride); stride = fold_convert (size_type_node, stride);
/* First check for overflow. Since an array of type character can /* First check for overflow. Since an array of type character can
have zero element_size, we must check for that before have zero element_size, we must check for that before
dividing. */ dividing. */
tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR, tmp = fold_build2_loc (input_location, TRUNC_DIV_EXPR,
sizetype, size_type_node,
TYPE_MAX_VALUE (sizetype), element_size); TYPE_MAX_VALUE (size_type_node), element_size);
tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond = gfc_unlikely (fold_build2_loc (input_location, LT_EXPR,
gfc_unlikely (fold_build2_loc (input_location, LT_EXPR, boolean_type_node, tmp, stride));
boolean_type_node, tmp, tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond,
stride)),
integer_one_node, integer_zero_node); integer_one_node, integer_zero_node);
tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond = gfc_unlikely (fold_build2_loc (input_location, EQ_EXPR,
gfc_unlikely (fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, element_size,
boolean_type_node, build_int_cst (size_type_node, 0)));
element_size, tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node, cond,
size_zero_node)),
integer_zero_node, tmp); integer_zero_node, tmp);
tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node, tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
*overflow, tmp); *overflow, tmp);
*overflow = gfc_evaluate_now (tmp, pblock); *overflow = gfc_evaluate_now (tmp, pblock);
size = fold_build2_loc (input_location, MULT_EXPR, sizetype, size = fold_build2_loc (input_location, MULT_EXPR, size_type_node,
stride, element_size); stride, element_size);
if (poffset != NULL) if (poffset != NULL)
...@@ -4190,11 +4187,11 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset, ...@@ -4190,11 +4187,11 @@ gfc_array_init_size (tree descriptor, int rank, int corank, tree * poffset,
if (integer_zerop (or_expr)) if (integer_zerop (or_expr))
return size; return size;
if (integer_onep (or_expr)) if (integer_onep (or_expr))
return gfc_index_zero_node; return build_int_cst (size_type_node, 0);
var = gfc_create_var (TREE_TYPE (size), "size"); var = gfc_create_var (TREE_TYPE (size), "size");
gfc_start_block (&thenblock); gfc_start_block (&thenblock);
gfc_add_modify (&thenblock, var, size_zero_node); gfc_add_modify (&thenblock, var, build_int_cst (size_type_node, 0));
thencase = gfc_finish_block (&thenblock); thencase = gfc_finish_block (&thenblock);
gfc_start_block (&elseblock); gfc_start_block (&elseblock);
......
2010-12-15 Jakub Jelinek <jakub@redhat.com> 2010-12-15 Jakub Jelinek <jakub@redhat.com>
PR fortran/46945
* gfortran.dg/pr46945.f90: New test.
PR debug/46815 PR debug/46815
* g++.dg/guality/pr46815.C: New test. * g++.dg/guality/pr46815.C: New test.
......
! PR fortran/46945
! { dg-do run }
! { dg-options "-O -ftree-vrp -fno-tree-ccp -fno-tree-fre" }
program pr46945
real, allocatable :: a(:,:,:)
integer :: n
n = 0
allocate (a(n,n,n))
end program pr46945
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment