From: Qing Zhao <qing.zhao@oracle.com>
To: Joseph Myers <joseph@codesourcery.com>,
richard Biener <rguenther@suse.de>
Cc: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
"siddhesh@gotplt.org" <siddhesh@gotplt.org>,
"keescook@chromium.org" <keescook@chromium.org>
Subject: Re: [PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832]
Date: Wed, 8 Feb 2023 15:06:48 +0000 [thread overview]
Message-ID: <2AB95191-B5D9-41AC-916A-C57ED20DF55E@oracle.com> (raw)
In-Reply-To: <e9e8fe5d-2c12-f3ad-3d1-c02d19b241af@codesourcery.com>
> On Feb 7, 2023, at 6:37 PM, Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Tue, 7 Feb 2023, Qing Zhao via Gcc-patches wrote:
>
>> Then, this routine (flexible_array_type_p) is mainly for diagnostic purpose.
>> It cannot be used to determine whether the structure/union type recursively
>> include a flexible array member at the end.
>>
>> Is my understanding correct?
>
> My comments were about basic principles of what gets diagnosed, and the
> need for different predicates in different contexts; I wasn't trying to
> assert anything about how that maps onto what functions should be used in
> what contexts.
Okay.
But I noticed that “flexible_array_type_p” later was moved from FE to
middle-end and put into tree.cc, tree.h as a general utility routine, and to
/* Determine whether TYPE is a structure with a flexible array member,
or a union containing such a structure (possibly recursively). */
However, since this routine does not cover the cases when the structure
with flexible array member was recursively embedded into structures, (which we
agreed that it should be considered as a flexible sized type).
Therefore, I feel that It might not be proper to include this routine in middle end
(and actually no other places In middle end use this routine so far).
That’s the reason I asked the previous question.
It might be better to move the routine “flexible_array_type_p” back from middle-end to
FE for the diagnosis purpose only.
>
>>>> 2. Only C99 standard flexible array member be included, [0] and [1] are
>>>> not included, for example:
>>>
>>> Obviously we can't diagnose use of structures with [1] trailing members,
>>> because it's perfectly valid to embed those structures at any position
>>> inside other structures. And the same is the case for the [0] extension
>>> when it's used to mean "empty array" rather than "flexible array".
>>
>> With the -fstrict-flex-arrays available, we should be able to diagnose
>> the flexible array member per gnu extension (i.e [0] or [1]) the same as [].
>
> There are different sorts of diagnostic that might be involved.
>
> * Simply having [0] or [1] at the end of a structure embedded in another
> structure isn't appropriate to diagnose, because [0] and [1] have
> perfectly good meanings in such a context that aren't trying to be
> flexible array members at all. [0] might be an empty type (possibly one
> that wouldn't be empty when built with a different configuration). [1]
> might be the use of arrays in C to produce a passed-by-reference type.
So, you mean, by default, Only having [] at the end of a structure embedded
in another structure is considered to be flexible sized type?
i.e.
struct flex { int n; int data[ ]; };
struct out_flex_end { int m; struct flex0 flex_data; };
struct outer_flex_end{ int p; struct out_flex_end0 out_flex_data; };
In the above, all “flex”, “out_flex_end” and “outer_flex_end” are flexible sized type.
But:
struct flex0 { int n; int data[0]; };
struct out_flex_end0 { int m; struct flex0 flex_data; };
struct outer_flex_end0 { int p; struct out_flex_end0 out_flex_data; };
In the above, only “flex0” is flexible sized type by default.
But “out_flex_end0” and “out_flex_end0” are Not considered as flexible sized type by default?
>
> * Trying to use such an embedded [0] or [1] array as if it were a flexible
> array member - i.e. accessing any member of the [0] array, or any member
> other than the [0] member of the [1] array - *is* a sign of the
> problematic use as a flexible array member, that might be appropriate to
> diagnose.
Yes, this was diagnosed with -Wstrict-flex-arrays + -fstrict-flex-arrays=n.
thanks.
Qing
> (Actually I'd guess the array index tends to be non-constant in
> accesses, and it would be odd to use a non-constant index when you mean
> that constant always to be 0, which it would need to be in the
> non-flexible case.)
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
next prev parent reply other threads:[~2023-02-08 15:06 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-31 14:11 [PATCH 0/2]PR101832: Handle component_ref to a structure/union field including flexible array member for builtin_object_size Qing Zhao
2023-01-31 14:11 ` [PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832] Qing Zhao
2023-02-01 11:41 ` Richard Biener
2023-02-01 14:19 ` Qing Zhao
2023-02-02 8:07 ` Richard Biener
2023-02-02 13:52 ` Qing Zhao
2023-02-02 13:54 ` Richard Biener
2023-02-02 14:38 ` Qing Zhao
2023-02-03 7:49 ` Richard Biener
2023-02-03 13:17 ` Qing Zhao
2023-02-06 9:31 ` Richard Biener
2023-02-06 14:38 ` Qing Zhao
2023-02-06 23:14 ` Joseph Myers
2023-02-07 14:54 ` Qing Zhao
2023-02-07 19:17 ` Joseph Myers
2023-02-07 19:57 ` Qing Zhao
2023-02-07 23:37 ` Joseph Myers
2023-02-08 15:06 ` Qing Zhao [this message]
2023-02-08 19:09 ` Joseph Myers
2023-02-08 19:20 ` Siddhesh Poyarekar
2023-02-08 20:51 ` Joseph Myers
2023-02-08 22:53 ` Qing Zhao
2023-02-08 23:18 ` Qing Zhao
2023-02-09 14:40 ` Qing Zhao
2023-02-09 16:46 ` Kees Cook
2023-02-10 15:25 ` Qing Zhao
2023-02-09 10:35 ` Richard Biener
2023-02-09 13:44 ` Qing Zhao
2023-02-07 15:28 ` Siddhesh Poyarekar
2023-02-07 15:38 ` Qing Zhao
2023-02-01 16:48 ` Siddhesh Poyarekar
2023-02-01 18:20 ` Qing Zhao
2023-01-31 14:11 ` [PATCH 2/2] Documentation Update Qing Zhao
2023-02-01 16:55 ` Siddhesh Poyarekar
2023-02-01 18:24 ` Qing Zhao
2023-02-01 18:57 ` Siddhesh Poyarekar
2023-02-01 19:19 ` Qing Zhao
2023-02-02 8:33 ` Richard Biener
2023-02-02 14:31 ` Qing Zhao
2023-02-02 17:05 ` Kees Cook
2023-02-03 15:56 ` Jeff Law
2023-02-03 4:25 ` Siddhesh Poyarekar
2023-02-03 14:52 ` Qing Zhao
2023-02-03 20:55 ` Joseph Myers
2023-02-03 22:38 ` Qing Zhao
2023-05-25 1:22 [V8][PATCH 0/2]Accept and Handle the case when a structure including a FAM nested in another structure Qing Zhao
2023-05-25 1:22 ` [PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832] Qing Zhao
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=2AB95191-B5D9-41AC-916A-C57ED20DF55E@oracle.com \
--to=qing.zhao@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.com \
--cc=keescook@chromium.org \
--cc=rguenther@suse.de \
--cc=siddhesh@gotplt.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).