public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Qing Zhao <qing.zhao@oracle.com>,
	Richard Biener <rguenther@suse.de>,
	Jakub Jelinek <jakub@redhat.com>
Cc: gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [RFC] how to handle the combination of -fstrict-flex-arrays + -Warray-bounds
Date: Sat, 22 Oct 2022 10:54:36 -0600	[thread overview]
Message-ID: <56fa59d1-75d3-6698-51fb-3806b9559397@gmail.com> (raw)
In-Reply-To: <695014B4-2A9E-49D6-BD40-4B24644FA1D6@oracle.com>

On 10/21/22 09:29, Qing Zhao wrote:
> Hi,
> 
> (FAM below refers to Flexible Array Members):
> 
> I need inputs on  how to handle the combination of -fstrict-flex-arrays + -Warray-bounds.
> 
> Our initial goal is to update -Warray-bounds with multiple levels of -fstrict-flex-arrays=N
> to issue warnings according to the different levels of “N”.
> However, after detailed study, I found that this goal was very hard to be achieved.
> 
> 1. -fstrict-flex-arrays and its levels
> 
> The new option -fstrict-flex-arrays has 4 levels:
> 
> level   trailing arrays
>          treated as FAM
> 
>    0     [],[0],[1],[n]          	the default without option
>    1     [],[0],[1]
>    2     [],[0]
>    3     []                      	the default when option specified without value
> 
> 2. -Warray-bounds and its levels
> 
> The option -Warray-bounds currently has 2 levels:
> 
> level   trailing arrays
>          treated as FAM
> 
>    1     [],[0],[1]			 the default when option specified without value
>    2     []                     	
> 
> i.e,
> When -Warray-bounds=1, it treats [],[0],[1] as FAM, the same level as -fstrict-flex-arrays=1;
> When -Warray-bounds=2, it only treat [] as FAM, the same level as -fstrict-flex-arrays=3;
> 
> 3. How to handle the combination of  -fstrict-flex-arrays and -Warray-bounds?
> 
> Question 1:  when -fstrict-flex-arrays does not present, the default is -strict-flex-arrays=0,
>                      which treats [],[0],[1],[n] as FAM, so should we update the default behavior
>                      of -Warray-bounds to treat any trailing array [n] as FAMs?
> 
> My immediate answer to Q1 is NO, we shouldn’t, that will be a big regression on -Warray-bounds, right?

Yes, it would disable -Warray-bounds in the cases where it warns
for past-the-end accesses to trailing arrays with two or more
elements.  Diagnosing those has historically (i.e., before recent
changes) been a design goal.

> 
> Question 2:  when -fstrict-flex-arrays=N1 and -Warray-bounds=N2 present at the same time,
>                       Which one has higher priority? N1 or N2?
> 
> -fstrict-flex-arrays=N1 controls how the compiler code generation treats the trailing arrays as FAMs, it seems
> reasonable to give higher priority to N1,

I tend to agree.  In other words, set N2' = min(N1, N2).

> However, then should we completely disable the level of -Warray-bounds
> N2 under such situation?
> 
> I really don’t know what’s the best way to handle the conflict  between N1 and N2.
> 
> Can we completely cancel the 2 levels of -Warray-bounds, and always honor the level of -fstrict-flex-arrays?
> 
> Any comments or suggestion will be helpful.

The recent -fstrict-flex-array changes aside, IIRC, there's only
a subtle distinction between the two -Warray-bounds levels (since
level 1 started warning on a number of instances that only level
2 used to diagnose a few releases ago).  I think that subset of
level 2 could be merged into level 1 without increasing the rate
of false positives.  Then level 2 could be assigned a new set of
potential problems to detect (such as past-the-end accesses to
trailing one-element arrays).

Martin

  reply	other threads:[~2022-10-22 16:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 15:29 Qing Zhao
2022-10-22 16:54 ` Martin Sebor [this message]
2022-10-24  7:30   ` Richard Biener
2022-10-24 14:51     ` Qing Zhao
2022-10-24 14:21   ` 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=56fa59d1-75d3-6698-51fb-3806b9559397@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=qing.zhao@oracle.com \
    --cc=rguenther@suse.de \
    /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).