public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "qing.zhao at oracle dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107952] tree-object-size: inconsistent size for flexible arrays nested in structs Date: Wed, 25 Jan 2023 15:14:55 +0000 [thread overview] Message-ID: <bug-107952-4-ws0G8EFlXE@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-107952-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107952 --- Comment #13 from Qing Zhao <qing.zhao at oracle dot com> --- > On Jan 25, 2023, at 2:32 AM, rguenther at suse dot de <gcc-bugzilla@gcc.gnu.org> wrote: >> >> A little confused here: >> when the structure with a trailing flexible-array member is a middle >> field of >> an outer structure, GCC extension will treat it as a flexible-array >> too? But the >> maximum size of this flexible-array will be bounded by the size of the >> padding >> of that field? >> Is the above understanding correct? > > That's correct - at least when using the get_ref_base_and_extent > API. I see that when using array_ref_flexible_size_p it doesn't > return true (but it's technically not _flexible_, we just treat it with > a bound size that doesn't match the declared bound). For the current array_ref_flexible_size_p, we include the following 3 cases: A. a ref to a flexible array member at the end of a structure; B. a ref to an array with a different type against the original decl; for example: short a[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; (*((char(*)[16])&a[0]))[i+8] C. a ref to an array that was passed as a parameter; for example: int test (uint8_t *p, uint32_t t[1][1], int n) { for (int i = 0; i < 4; i++, p++) t[i][0] = …; It basically mean: return true if REF is to an array whose actual size might be larger than its upper bound implies. I feel that the case "when the structure with a trailing flexible-array member is a middle field of an outer structure” still fit here, but not very sure, need more thinking... > > The first is handled by the function just fine, No, even the first case is not recognized by the current “array_ref_flexible_size_p”, it’s not been identified as a flexible array right now. Shall we include this case into “array_ref_flexible_size_p”? (It’s a GCC extension). > it's the second with the bound size that's not and that isn't a good fit there, > though we do handle padding to the end of a declaration where > we return true. > >> Handle them separately instead? > > I'm not sure how important it is to hande the middle array > extending to padding, ISTR there was some real world code > "miscompiled" when treating the array domain as written. We can leave the 2nd case in a later time to resolve -:) >
next prev parent reply other threads:[~2023-01-25 15:14 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-12-02 14:04 [Bug tree-optimization/107952] New: " siddhesh at gcc dot gnu.org 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 [this message] 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-ws0G8EFlXE@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: linkBe 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).