[Bug c++/93789] [8/9/10 Regression] internal compiler error: in tree_to_uhwi, at tree.c:7361

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Feb 27 02:58:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93789

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:1231f71f96a4e461f94394b4fb8cfa25587fbd96

commit r10-6881-g1231f71f96a4e461f94394b4fb8cfa25587fbd96
Author: Marek Polacek <polacek@redhat.com>
Date:   Wed Feb 26 15:02:25 2020 -0500

    c++: Fix ICE with invalid array bounds [PR93789]

    r7-2111 introduced maybe_constant_value in cp_fully_fold.
    maybe_constant_value uses cxx_eval_outermost_constant_expr, which
    can clear TREE_CONSTANT:
    6510   else if (non_constant_p && TREE_CONSTANT (r))
    [...]
    6529       TREE_CONSTANT (r) = false;

    In this test the array size is '(long int) "h"'.  This used to be
    TREE_CONSTANT but given the change above, the flag will be cleared
    when we cp_fully_fold the array size in compute_array_index_type_loc.
    That means we don't emit an error in the
    10391   else if (TREE_CONSTANT (size)
    block in the same function, and we go on.  Then we compute ITYPE
    using cp_build_binary_op and use maybe_constant_value on it and
    suddenly we have something that's TREE_CONSTANT again.  And then we
    crash in reshape_init_array_1 in tree_to_uhwi, because what we have
    doesn't fit in an unsigned HWI.

    icc accepts this code, but since we used to reject it, I see no desire
    to make this work, so don't use the folded result when we've lost
    the TREE_CONSTANT flag while evaluating the size.

    2020-02-26  Marek Polacek  <polacek@redhat.com>

        PR c++/93789 - ICE with invalid array bounds.
        * decl.c (compute_array_index_type_loc): Don't use the folded
        size when folding cleared TREE_CONSTANT.

        * g++.dg/ext/vla22.C: New test.


More information about the Gcc-bugs mailing list