public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/106297] [12/13 Regression] stringop-overflow misbehaviour on atomic since r12-4725-g88b504b7a8c5affb
Date: Thu, 28 Jul 2022 14:33:16 +0000	[thread overview]
Message-ID: <bug-106297-4-tf1yE4SuDY@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106297-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106297

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-reduction             |
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This boils down to:
struct S { long a, b, c; char d[0], e[0]; };
extern struct S s[1];

int
foo (int n)
{
  int i;
  for (i = 0; i < n; i++)
    if ((__atomic_load_n (&s[i].c, 0) & s[i].b) == s[i].b)
      break;
  return i;
}

As the array has just a single element, this is UB if n > 1, but for some
reason we decide in the cunroll pass to completely unroll the loop.  The first
iteration is full, the second one has the __atomic_load_8 call plus
__builtin_unreachable right after it.
Bet we only think that s[i_14].b for i_14 1 will be UB, while __atomic_load_8
(&s[i].c, 0) is fine.  Even that is UB, even just forming the address, and even
if not - say the atomic would be on &s[i].a - it is accessing that member.
Though, for the atomic load we have
  _8 = (sizetype) i_14;
  _7 = _8 * 24;
  _15 = _7 + 16;
  _1 = &s + _15;
  _2 = __atomic_load_8 (_1, 0);
in the IL while for the load everything in one stmt:
  _4 = s[i_14].b;

The warning is on dead code here, the second __atomic_load_8 which would happen
only if  is > 1.

  parent reply	other threads:[~2022-07-28 14:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 14:05 [Bug c/106297] New: stringop-overflow misbehaviour on atomic chipitsine at gmail dot com
2022-07-14 16:05 ` [Bug tree-optimization/106297] " pinskia at gcc dot gnu.org
2022-07-15  2:33 ` chipitsine at gmail dot com
2022-07-15  8:05 ` [Bug tree-optimization/106297] [12/13 Regression] stringop-overflow misbehaviour on atomic since r12-4725-g88b504b7a8c5affb marxin at gcc dot gnu.org
2022-07-15  8:05 ` marxin at gcc dot gnu.org
2022-07-18  7:27 ` rguenth at gcc dot gnu.org
2022-07-25 15:03 ` rguenth at gcc dot gnu.org
2022-07-28 14:33 ` jakub at gcc dot gnu.org [this message]
2022-07-28 15:28 ` msebor at gcc dot gnu.org
2023-05-08 12:25 ` [Bug tree-optimization/106297] [12/13/14 " rguenth at gcc dot gnu.org

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-106297-4-tf1yE4SuDY@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: 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).