On 2/26/19 3:44 PM, Jakub Jelinek wrote:
Hi!

Seems valid_constant_size_p has been written with the expectation that only
sizetype/ssizetype constants will be passed to it, otherwise it couldn't
ever just blindly test tree_int_cst_sign_bit (size) for unsigned
INTEGER_CSTs and complain cst_size_too_big.
Unfortunately a recent patch started using this function even on other
types, and the comment explicitly talk about it being done on
pre-conversion to sizetype:
       /* The expression in a noptr-new-declarator is erroneous if it's of
          non-class type and its value before converting to std::size_t is
          less than zero. ... If the expression is a constant expression,
          the program is ill-fomed.  */
       if (TREE_CODE (cst_nelts) == INTEGER_CST
           && !valid_array_size_p (input_location, cst_nelts, NULL_TREE,
                                   complain & tf_error))
         return error_mark_node;
E.g. __int128 negative value could fit just fine after cast to sizetype,
etc.

So, instead of changing the C++ FE to only complain about negative cst_elts
normally and fold_convert everything to sizetype before checking, this patch
attempts to deal with non-{,s}sizetype constants.  Negative (signed)
constants are always rejected as before, newly constants that don't fit into
uhwi are rejected after that check regardless of signedness and anything
larger or equal than SIZE_MAX / 2 is also rejected as too big.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-02-26  Jakub Jelinek  <ja...@redhat.com>

        PR c++/89507
        * tree.c (valid_constant_size_p): Deal with size INTEGER_CSTs
        with types other than sizetype/ssizetype.

Looks good to me.

Jason

Reply via email to