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 middle-end/108721] [10/11/12/13 Regression] csmith: really old bug with -O2
Date: Thu, 16 Feb 2023 12:07:59 +0000	[thread overview]
Message-ID: <bug-108721-4-h8nUkUoJzF@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-108721-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
In the reduced testcase there is certainly an aliasing violation.
struct {
  unsigned f0
} g_95 = {65531};
...
*g_412 = &g_95;
...
  --g_95.f0;
  *g_86 = g_613 || 0;
  *g_412 = 0;
  short *l_873 = &g_95;
  --*l_873;
even after making g_412 unsigned *g_412 = &g_95.f0; it gets different results,
but
while short *l_873 = &g_95.f0; does as well, doing
  typedef short sa __attribute__((may_alias));
  sa *l_873 = &g_95.f0;
one gets the same result.
Now, in the original testcase it actually uses
union U0 {
   uint16_t f0;
   int64_t f1;
   int64_t f2;
   uint32_t f3;
};
static union U0 g_95 = {65531UL};
but then has
static int64_t *g_279 = &g_95.f2;
...
    int64_t *l_939 = &g_95.f2;
...
        uint16_t *l_873 = &g_95.f0;
...
                uint32_t *l_933[8] =
{&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3,&g_95.f3};
...
        int64_t *l_425 = &g_95.f2;
...
        uint16_t *l_597 = &g_95.f0;
etc.  Now, all of this doesn't necessarily mean it is UB, but it is a strong
indication that it very likely is.  Standard C/C++ doesn't allow type punning
through union, only one of the members can be active at a time, GCC allows it,
but for aliasing requires that accesses have the union type visible to the
compiler on the access.  Taking addresses of different union members means that
most likely that isn't followed, UB would be whenever some union member is
stored and another one read through a pointer without the union in access path
etc.

Now, I think some of the readings of the standard say that whenever say
uint16_t and uint32_t appear in some union anywhere, one basically needs to
treat them as the same alias set, but such reading makes TBAA totally useless. 
So if csmith follows that reading, it is indeed unsafe for TBAA.

  parent reply	other threads:[~2023-02-16 12:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 16:51 [Bug c/108721] New: " dcb314 at hotmail dot com
2023-02-08 16:55 ` [Bug middle-end/108721] " pinskia at gcc dot gnu.org
2023-02-08 16:58 ` [Bug c/108721] [10/11/12/13 Regression] " jakub at gcc dot gnu.org
2023-02-15 17:24 ` [Bug middle-end/108721] " dcb314 at hotmail dot com
2023-02-16 12:07 ` jakub at gcc dot gnu.org [this message]
2023-02-16 12:31 ` jakub 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-108721-4-h8nUkUoJzF@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).