public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "qinzhao at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/101836] __builtin_object_size(P->M, 1) where M is an array and the last member of a struct fails
Date: Wed, 08 Jun 2022 14:09:50 +0000	[thread overview]
Message-ID: <bug-101836-4-ObNBFJlkRo@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101836-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #12 from qinzhao at gcc dot gnu.org ---
In the current tree-object-size.cc, "addr_object_size", it's clearly state the
following:

 607               /* For &X->fld, compute object size only if fld isn't the
last
 608                  field, as struct { int i; char c[1]; } is often used
instead
 609                  of flexible array member.  */

and these part of codes were added back to 2009 with commit
eb9ed98a951531f7fc40c69883b3285d58b168b2.

it's reasonable to add a new option -fstrict-flex-arrays to remove the
"trailing array is a flex array" assumptions in current GCC. 

and the following utility routine that is added in tree.[h|cc] in 2020 can be
used to identify whether a trailing array member reference is a flexible array
or not:


/* Describes a "special" array member due to which component_ref_size
   returns null.  */
enum struct special_array_member
  {
   none,      /* Not a special array member.  */
   int_0,     /* Interior array member with size zero.  */
   trail_0,   /* Trailing array member with size zero.  */
   trail_1    /* Trailing array member with one element.  */
  };


/* Determines the size of the member referenced by the COMPONENT_REF
   REF, using its initializer expression if necessary in order to
   determine the size of an initialized flexible array member.
   If non-null, set *ARK when REF refers to an interior zero-length
   array or a trailing one-element array.
   Returns the size as sizetype (which might be zero for an object
   with an uninitialized flexible array member) or null if the size
   cannot be determined.  */

tree
component_ref_size (tree ref, special_array_member *sam /* = NULL */)

  parent reply	other threads:[~2022-06-08 14:09 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-09 23:25 [Bug c/101836] New: " kees at outflux dot net
2021-08-09 23:34 ` [Bug c/101836] " pinskia at gcc dot gnu.org
2021-08-09 23:35 ` pinskia at gcc dot gnu.org
2021-08-10  1:19 ` kees at outflux dot net
2021-10-13  2:11 ` msebor at gcc dot gnu.org
2021-10-13  2:11 ` [Bug middle-end/101836] " msebor at gcc dot gnu.org
2021-10-13  3:11 ` siddhesh at gotplt dot org
2022-05-26 16:34 ` qinzhao at gcc dot gnu.org
2022-05-27  1:45 ` siddhesh at gcc dot gnu.org
2022-05-27 14:27 ` qinzhao at gcc dot gnu.org
2022-05-27 21:01 ` kees at outflux dot net
2022-05-27 21:08 ` kees at outflux dot net
2022-05-27 21:15 ` kees at outflux dot net
2022-06-08 14:09 ` qinzhao at gcc dot gnu.org [this message]
2022-06-08 15:37 ` kees at outflux dot net
2022-06-08 16:06 ` qinzhao at gcc dot gnu.org
2022-06-10 20:15 ` qinzhao at gcc dot gnu.org
2022-06-10 20:24 ` qinzhao at gcc dot gnu.org
2022-06-11  8:21 ` kees at outflux dot net
2022-06-13 14:48 ` msebor at gcc dot gnu.org
2022-06-13 18:12 ` kees at outflux dot net
2022-06-13 22:27 ` msebor at gcc dot gnu.org
2022-06-14  0:00 ` kees at outflux dot net
2022-06-14  5:09 ` siddhesh at gcc dot gnu.org
2022-06-14  5:21 ` siddhesh at gcc dot gnu.org
2022-06-14  7:25 ` jakub at gcc dot gnu.org
2022-06-14 15:00 ` qinzhao at gcc dot gnu.org
2022-06-14 15:39 ` siddhesh at gcc dot gnu.org
2022-06-14 16:02 ` qing.zhao at oracle dot com
2022-06-14 16:17 ` jakub at gcc dot gnu.org
2022-06-14 21:03 ` qinzhao at gcc dot gnu.org
2022-06-14 21:12 ` jakub at gcc dot gnu.org
2022-06-25  0:52 ` foom at fuhm dot net
2022-06-27 14:01 ` qinzhao at gcc dot gnu.org
2022-07-06 16:16 ` foom at fuhm dot net
2022-07-06 16:49 ` kees at outflux dot net
2022-07-06 17:53 ` qinzhao at gcc dot gnu.org
2022-07-06 19:30 ` foom at fuhm dot net
2022-07-06 19:46 ` foom at fuhm dot net
2022-07-06 20:01 ` qinzhao at gcc dot gnu.org
2022-07-06 20:05 ` qinzhao at gcc dot gnu.org
2022-07-22 22:33 ` isanbard at gmail dot com
2022-07-23  1:57 ` kees at outflux dot net
2022-10-07 17:44 ` cvs-commit at gcc dot gnu.org
2022-12-21 20:47 ` qinzhao at gcc dot gnu.org
2023-06-21 19:47 ` qinzhao 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-101836-4-ObNBFJlkRo@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).