public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/109215] [13 Regression] wrong warning: array subscript 0 is outside the bounds of an interior zero-length array ‘struct lock_class_key[3]’
Date: Tue, 21 Mar 2023 10:07:14 +0000	[thread overview]
Message-ID: <bug-109215-4-wGY77dwE1w@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109215-4@http.gcc.gnu.org/bugzilla/>

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

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

https://gcc.gnu.org/g:03041e0361cbdd7f541f2f39060759aad866ed58

commit r13-6782-g03041e0361cbdd7f541f2f39060759aad866ed58
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 21 11:06:20 2023 +0100

    tree: Fix up component_ref_sam_type handling of arrays of 0 sized elements
[PR109215]

    Our documentation sadly talks about elt_type arr[0]; as zero-length arrays,
    not arrays with zero elements.  Unfortunately, those aren't the only arrays
    which can have zero size, the same size can be also result of zero-length
    element, like in GNU C struct whatever {} or in GNU C/C++ if the element
    type is [0] array or combination thereof (dunno if Ada doesn't allow
    something similar too).  One can't do much with them, taking address of
    their elements, (no-op) copying of the elements in and out.  But they
    behave differently from arr[0] arrays e.g. in that using non-zero indexes
    in them (as long as they are within bounds as for normal arrays) is valid.

    I think this naming inaccuracy resulted in Martin designing
    special_array_member in an inconsistent way, mixing size zero array members
    with array members of one or two or more elements and then using the
    size zero interchangeably with zero elements.

    The following patch changes that (but doesn't do any
    documentation/diagnostics renaming, as this is really a corner case),
    such that int_0/trail_0 for consistency is just about [0] arrays
    plus [] for the latter, not one or more zero sized elements case.

    The testcase has one xfailed case for where perhaps in later GCC versions
    we could add extra code to handle it, for some reason we don't diagnose
    out of bounds accesses for the zero sized elements cases.  It will be
    harder because e.g. FRE will canonicalize &var.fld[0] and &var.fld[10]
    to just one of them because they are provably the same address.
    But the important thing is to fix this regression (where we warn on
    completely valid code in the Linux kernel).  Anyway, for further work
    on this we don't really need any extra help from special_array_member,
    all code can just check integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (type))),
    it doesn't depend on the position of the members etc.

    2023-03-21  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/109215
            * tree.h (enum special_array_member): Adjust comments for int_0
            and trail_0.
            * tree.cc (component_ref_sam_type): Clear zero_elts if memtype
            has zero sized element type and the array has variable number of
            elements or constant one or more elements.
            (component_ref_size): Adjust comments, formatting fix.

            * gcc.dg/Wzero-length-array-bounds-3.c: New test.

  parent reply	other threads:[~2023-03-21 10:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 14:26 [Bug c/109215] New: " ubizjak at gmail dot com
2023-03-20 14:27 ` [Bug c/109215] " ubizjak at gmail dot com
2023-03-20 15:11 ` [Bug tree-optimization/109215] [13 Regression] wrong " pinskia at gcc dot gnu.org
2023-03-20 15:11 ` pinskia at gcc dot gnu.org
2023-03-20 16:40 ` jakub at gcc dot gnu.org
2023-03-20 17:20 ` jakub at gcc dot gnu.org
2023-03-20 17:42 ` jakub at gcc dot gnu.org
2023-03-20 18:51 ` jakub at gcc dot gnu.org
2023-03-21  8:11 ` rguenth at gcc dot gnu.org
2023-03-21 10:07 ` cvs-commit at gcc dot gnu.org [this message]
2023-03-21 10:07 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109215-4-wGY77dwE1w@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).