[PATCH] Use size_type_node instead of sizetype for stride overflow checking (PR fortran/46945)

Janne Blomqvist blomqvist.janne@gmail.com
Wed Dec 15 18:59:00 GMT 2010


On Wed, Dec 15, 2010 at 20:04, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> Using sizetype for testing whether stride * element_size will overflow
> is wrong, because unlike all sane unsigned types, sizetype doesn't have
> modulo semantics, but instead has undefined overflow.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

You've converted size_zero_node into build_int_cst (size_type_node,
0), but you missed one case, so I presume you'd want

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 84e6005..f93967e 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -4169,10 +4169,11 @@ gfc_array_init_size (tree descriptor, int
rank, int corank, tree * poffset,
                                                        stride)),
                         integer_one_node, integer_zero_node);
   tmp = fold_build3_loc (input_location, COND_EXPR, integer_type_node,
-                        gfc_unlikely (fold_build2_loc (input_location, EQ_EXPR,
-                                                       boolean_type_node,
-                                                       element_size,
-                                                       size_zero_node)),
+                        gfc_unlikely (fold_build2_loc
+                                      (input_location, EQ_EXPR,
+                                       boolean_type_node,
+                                       element_size,
+                                       build_int_cst (size_type_node, 0))),
                         integer_zero_node, tmp);
   tmp = fold_build2_loc (input_location, PLUS_EXPR, integer_type_node,
                         *overflow, tmp);

on top of your patch? With that change, ok for trunk



-- 
Janne Blomqvist



More information about the Gcc-patches mailing list