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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:f72e3d8c9ffb81d25d4fdba10056cd2197e22d64

commit r11-7275-gf72e3d8c9ffb81d25d4fdba10056cd2197e22d64
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Thu Feb 18 09:45:19 2021 +0100

    array-bounds: Fix up ICE on overaligned variables [PR99109]

    check_mem_ref builds artificial arrays for variables that don't have
    array type.
    The C standard says:
    "For the purposes of these operators, a pointer to an object that is not an
element of an
    array behaves the same as a pointer to the first element of an array of
length one with the
    type of the object as its element type."
    so it isn't completely wrong and does simplify the function.
    But, layout_type can fail if the size of the element type is not a multiple
    of its alignment (i.e. overaligned types) and we then ICE because of that.

    The following patch uses TYPE_MAIN_VARIANT in those cases instead, but only
    for the types that need it, as for the diagnostics it is better to use the
    typedef names etc. that were really used in the source if possible.

    2021-02-18  Jakub Jelinek  <ja...@redhat.com>

            PR middle-end/99109
            * gimple-array-bounds.cc (build_zero_elt_array_type): Rename to ...
            (build_printable_array_type): ... this.  Add nelts argument.  For
            overaligned eltype, use TYPE_MAIN_VARIANT (eltype) instead.  If
            nelts, call build_array_type_nelts.
            (array_bounds_checker::check_mem_ref): Use
build_printable_array_type
            instead of build_zero_elt_array_type and build_array_type_nelts.

            * g++.dg/warn/Warray-bounds-17.C: New test.

Reply via email to