public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "siddhesh at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/107952] New: tree-object-size: inconsistent size for flexible arrays nested in structs
Date: Fri, 02 Dec 2022 14:04:50 +0000	[thread overview]
Message-ID: <bug-107952-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 107952
           Summary: tree-object-size: inconsistent size for flexible
                    arrays nested in structs
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: siddhesh at gcc dot gnu.org
  Target Milestone: ---

With -fstrict-flex-arrays, there is a clearer definition of what constitutes
flexible array members, controlled by the frontend.  tree-object-size however
doesn't seem to handle this well enough when the flex array is nested.  e.g.:

typedef struct {
  char pad;
  char data[8];
} F2;

typedef struct {
  unsigned pad;
  F2 flex;
} S2;

#define NULL (void *) 0

__SIZE_TYPE__
nested_flexarray (__SIZE_TYPE__ n)
{
  S2 *p = (S2 *) __builtin_malloc (n);

  return __builtin_dynamic_object_size (p->flex.data, 1);
}

__SIZE_TYPE__
nested_flexarray2 (S2 *p)
{
  return __builtin_dynamic_object_size (p->flex.data, 1);
}

The current behaviour is to treat data as a flex array and nested_flexarray
returns the size as if it were a flex array.  nested_flexarray2 however returns
the subscripted size, thinking of it as a fixed array, which should not be the
expected behaviour with -fstrict-flex-arrays=0.  Instead it should return -1
for maximum size and perhaps 8 as minimum size.

If F2 is changed to:

typedef struct {
  char pad;
  char data[0];
} F2;

the current behaviour ends up returning 0 in both cases, which is incorrect. 
Again, it should return the size as if it were a flex array in nested_flexarray
and -1 for maximum size for nested_flexarray2.

I have a patch that does this, but I need to fix up tests that currently expect
older behaviour and wanted to get some consensus before I fixed them up.

             reply	other threads:[~2022-12-02 14:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 14:04 siddhesh at gcc dot gnu.org [this message]
2022-12-05  8:05 ` [Bug tree-optimization/107952] " rguenth at gcc dot gnu.org
2022-12-05 12:46 ` siddhesh at gcc dot gnu.org
2022-12-05 13:15 ` jakub at gcc dot gnu.org
2022-12-05 15:11 ` rguenther at suse dot de
2022-12-05 15:28 ` siddhesh at gcc dot gnu.org
2023-01-23 19:39 ` qinzhao at gcc dot gnu.org
2023-01-23 19:44 ` qinzhao at gcc dot gnu.org
2023-01-23 21:30 ` siddhesh at gcc dot gnu.org
2023-01-24 10:04 ` rguenth at gcc dot gnu.org
2023-01-24 15:24 ` qing.zhao at oracle dot com
2023-01-25  7:32 ` rguenther at suse dot de
2023-01-25 12:44 ` siddhesh at gcc dot gnu.org
2023-01-25 15:14 ` qing.zhao at oracle dot com
2023-01-25 16:12 ` siddhesh at gcc dot gnu.org
2023-01-25 16:40 ` qing.zhao at oracle dot com
2023-01-25 21:16 ` siddhesh at gcc dot gnu.org
2023-01-25 21:43 ` qinzhao at gcc dot gnu.org
2023-01-26  7:20 ` rguenth at gcc dot gnu.org
2023-01-26 22:13 ` qinzhao at gcc dot gnu.org
2023-01-27  7:46 ` rguenther at suse dot de

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-107952-4@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).