public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Martin Sebor <msebor@gmail.com>
Cc: Dumitru Ceara <dceara@redhat.com>, gcc-help@gcc.gnu.org
Subject: Re: Potentially false-positive -Wstringop-overflow= warning with gcc >= 11.1
Date: Mon, 31 Jan 2022 16:01:10 -0600	[thread overview]
Message-ID: <20220131220110.GQ614@gate.crashing.org> (raw)
In-Reply-To: <ea3c3f08-f05f-aa7b-5510-f77a87c3914f@gmail.com>

On Mon, Jan 31, 2022 at 02:49:43PM -0700, Martin Sebor wrote:
> Some statements are also isolated from the source code even when they
> don't appear there, or appear with different arguments.  That's also
> what happens in this case: GCC replaces the memcpy call and
> the subsequent store with two: one pair is valid  and another pair
> of invalid statements.  Here's the problem in the IL the warning
> sees and points out:
> 
>   <bb 4> [count: 0]:
>   memcpy (4B, &somedata[0], 6);        <<< -Warray-bounds
>   MEM[(struct hdr2 *)0B].h21 ={v} 0;   <<< causes path isolation
>   __builtin_trap ();                       and trap to be added

Yup.  And GCC does not (yet) consider that memcpy to be UB itself, or
the trap would be moved there, removing the warning.  This may be the
best we can get :-)

(This of course requires the analysis to be always correct :-) )

> More to your point, it's also an example where warnings issued for
> code that's reachable only under some conditions make it seem like
> they point out unconditional bugs.

Yes, this is hard to understand often.  It makes it easy to think GCC
is wrong and the user code is correct (esp. for the user who wrote it).


Segher

  reply	other threads:[~2022-01-31 22:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28 15:01 Dumitru Ceara
2022-01-28 15:27 ` Segher Boessenkool
2022-01-28 16:16   ` Dumitru Ceara
2022-01-28 17:37     ` Segher Boessenkool
2022-01-31 21:49     ` Martin Sebor
2022-01-31 22:01       ` Segher Boessenkool [this message]
2022-02-01  8:21         ` Jonathan Wakely
2022-02-01  5:18       ` Richard Sandiford
2022-02-01 14:42         ` Segher Boessenkool
2022-02-01 23:54         ` Martin Sebor
2022-02-02 10:12           ` Jonathan Wakely
2022-02-02 18:33             ` Segher Boessenkool
2022-02-02 20:44               ` Jonathan Wakely
2022-02-02 18:23           ` Segher Boessenkool

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=20220131220110.GQ614@gate.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=dceara@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=msebor@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).