From: Martin Sebor <msebor@gmail.com>
To: Richard Biener <richard.guenther@gmail.com>,
Qing Zhao <qing.zhao@oracle.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
gcc-patches Paul A Clarke via <gcc-patches@gcc.gnu.org>,
kees Cook <keescook@chromium.org>
Subject: Re: [GCC 13][PATCH] PR101836: Add a new option -fstrict-flex-array[=n] and use it in __builtin_object_size
Date: Tue, 28 Jun 2022 10:21:57 -0600 [thread overview]
Message-ID: <c160eb6d-a887-99ff-05cd-382298fb4d02@gmail.com> (raw)
In-Reply-To: <CAFiYyc21atAmFmRh64RDWhFeHj3BJYuk1gtmxRxNHa17RzrZWQ@mail.gmail.com>
On 6/28/22 01:16, Richard Biener wrote:
> On Mon, Jun 27, 2022 at 4:20 PM Qing Zhao via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>>
>> Hi,
>>
>> Per our discussion in the bug report, I came up with the following patch:
>>
>> =======
>>
>> PR101836: Add a new option -fstrict-flex-array[=n]
>>
>> Add the new option and use it in __builtin_object_size.
>>
>> Treat the trailing array of a structure as a flexible array member in a
>> stricter way. The value of 'n' controls the level of strictness.
>> 'n'=0 is the least strict, all trailing arrays of structures are treated
>> as flexible array members; This is the default behavior of GCC without specify
>> this option.
>> 'n'=3 is the strictest, only when the trailing array is declared as a
>> flexible array member per C99 standard onwards ([]), it is treated as a
>> flexible array member;
>> There are two more levels in between 0 and 3, which are provided to support
>> older codes that use GCC zero-length array extension ([0]), or one-size array as
>> flexible array member ([1]):
>> When 'n' is 1, the trailing array is treated as a flexible array member
>> when it is declared as either [], [0], or [1];
>> When 'n' is 2, the trailing array is treated as a flexible array member
>> when it is declared as either [], or [0].
>>
>> There are other places in GCC that conservatively treat flexible array members.
>> A follow-up patch will make -ftrict-flex-array option to control all these
>> places consistently.
>>
>> Bootstrapped and regression tested on both X86 and aarch64, no issues.
>>
>> Any comment and suggestion?
>
> Since this aims at the C or C++ frontends but the middle-end eventually consumes
> this it would be much nicer to encode this in the types themselves.
> Since the least
> strict reading is the default right now it would be a flag (on the
> FIELD_DECL I suppose)
> like DECL_NOT_FLEXARRAY or DECL_FIXED_SIZE? Alternatively the flag could
> also be on the record type enclosing the trailing array member (but
> type sharing might
> make this more difficult in the end).
>
> There's also array_at_struct_end_p which is supposed to be the main
> query interface
> for this (but it seems people sneaked in more variants with eventually
> different semantics ... :/)
The conservative array_at_struct_end_p has historically been used
for codegen. component_ref_size was added as a separate function
with more flexible (including stricter) semantics to implement
warnings without running the risk of interfering with codegen.
Martin
>
> Richard.
>
>
>
>> Okay for commit to Gcc13?
>>
>> thanks.
>>
>> Qing
>>
>> =======================
>>
>> gcc/
>>
>> PR tree-optimization/101836
>> * common.opt (fstrict-flex-array, fstrict-flex-array=): New options.
>> * doc/invoke.texi (-fstrict-flex-array, -fstrict-flex-array=): Document.
>> * tree-object-size.cc (addr_object_size): Call is_flexible_array_p to
>> check whether an array is a flexible array.
>> * tree.cc (special_array_member_type): New routine.
>> (is_flexible_array_p): New routine.
>> (component_ref_size): Call special_array_member_type to decide the
>> type of special array member.
>> * tree.h (enum struct special_array_member): Add is_vla, trail_flex.
>> (special_array_member_type): New prototype.
>> (is_flexible_array_p): New prototype.
>>
>> gcc/testsuite/
>>
>> PR tree-optimization/101836
>> * gcc.dg/pr101836.c: New test.
>> * gcc.dg/pr101836_1.c: New test.
>> * gcc.dg/pr101836_2.c: New test.
>> * gcc.dg/pr101836_3.c: New test.
>> * gcc.dg/pr101836_4.c: New test.
>> * gcc.dg/pr101836_5.c: New test.
>>
>>
>> The complete patch is:
>>
prev parent reply other threads:[~2022-06-28 16:22 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 14:19 Qing Zhao
2022-06-28 7:16 ` Richard Biener
2022-06-28 15:03 ` Qing Zhao
2022-06-28 15:08 ` Jakub Jelinek
2022-06-28 15:59 ` Qing Zhao
2022-06-28 16:43 ` Jakub Jelinek
2022-06-28 18:15 ` Qing Zhao
2022-06-28 18:22 ` Jakub Jelinek
2022-06-28 18:29 ` Qing Zhao
2022-06-28 18:49 ` Jakub Jelinek
2022-06-28 19:01 ` Qing Zhao
2022-06-29 21:14 ` Martin Sebor
2022-06-30 14:07 ` Qing Zhao
2022-06-30 14:24 ` Richard Biener
2022-06-30 15:31 ` Qing Zhao
2022-06-30 17:03 ` Jakub Jelinek
2022-06-30 19:30 ` Qing Zhao
2022-07-01 6:49 ` Richard Biener
2022-07-01 12:55 ` Qing Zhao
2022-07-01 12:58 ` Richard Biener
2022-07-01 13:40 ` Qing Zhao
2022-07-01 12:59 ` Jakub Jelinek
2022-07-01 14:01 ` Qing Zhao
2022-07-01 15:32 ` Martin Sebor
2022-07-04 6:49 ` Richard Biener
2022-07-06 14:20 ` Qing Zhao
2022-07-07 8:02 ` Richard Biener
2022-07-07 13:33 ` Qing Zhao
2022-06-29 20:45 ` Qing Zhao
2022-06-28 16:21 ` Martin Sebor [this message]
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=c160eb6d-a887-99ff-05cd-382298fb4d02@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=keescook@chromium.org \
--cc=qing.zhao@oracle.com \
--cc=richard.guenther@gmail.com \
/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).