public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/113630] [11/12/13/14 Regression] -fno-strict-aliasing introduces out-of-bounds memory access
Date: Mon, 29 Jan 2024 08:11:15 +0000	[thread overview]
Message-ID: <bug-113630-4-chmMQdBy1X@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113630-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Confirmed.
> 
> I really think what PRE does is correct here since we have an aliasing set
> of 0 for both. Now what is incorrect is hoist_adjacent_loads which cannot do
> either of any of the aliasing sets are 0 ...
> 
> 
> 
> I think even the function below is valid for non-strict aliasing:
> ```
> int __attribute__((noipa,noinline))
> f(struct S *p, int c, int d)
> {
>   int r;
>   if (c)
>     {
>         r = ((struct M*)p)->a;
>     }
>   else
>     r = ((struct M*)p)->b;
>   return r;
> }
> ```
> 
> That is hoist_adjacent_loads is broken for non-strict-aliasing in general
> and has been since 4.8.0 when it was added (r0-117275-g372a6eb8d991eb).

It looks it relies on

      /* The zeroth operand of the two component references must be
         identical.  It is not sufficient to compare get_base_address of
         the two references, because this could allow for different
         elements of the same array in the two trees.  It is not safe to
         assume that the existence of one array element implies the
         existence of a different one.  */
      if (!operand_equal_p (TREE_OPERAND (ref1, 0), TREE_OPERAND (ref2, 0), 0))
        continue;

for the correctness test.  Note the MEM accesses are of size sizeof (struct M).

With -fno-strict-aliasing we're not wiping that detail so I think it _is_
a bug in PRE that it merges the two accesses.

I'll have a more detailed look.

  parent reply	other threads:[~2024-01-29  8:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-27 17:34 [Bug tree-optimization/113630] New: " kristerw at gcc dot gnu.org
2024-01-27 17:42 ` [Bug tree-optimization/113630] " pinskia at gcc dot gnu.org
2024-01-27 23:34 ` [Bug tree-optimization/113630] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2024-01-27 23:42 ` pinskia at gcc dot gnu.org
2024-01-28  0:11 ` pinskia at gcc dot gnu.org
2024-01-29  8:04 ` rguenth at gcc dot gnu.org
2024-01-29  8:11 ` rguenth at gcc dot gnu.org [this message]
2024-01-31 11:35 ` cvs-commit at gcc dot gnu.org
2024-01-31 11:35 ` [Bug tree-optimization/113630] [11/12/13 " rguenth at gcc dot gnu.org
2024-05-06 13:15 ` cvs-commit at gcc dot gnu.org
2024-05-06 13:18 ` [Bug tree-optimization/113630] [11/12 " 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-113630-4-chmMQdBy1X@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).