public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/94337] New: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning
Date: Thu, 26 Mar 2020 02:03:46 +0000	[thread overview]
Message-ID: <bug-94337-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 94337
           Summary: Incorrect "dereferencing type-punned pointer will
                    break strict-aliasing rules" warning
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Consider the following example.

#include <stdio.h>

struct s1
{
  int a;
};

struct s2
{
  int a, b;
};

int main (void)
{
  union {
    struct s1 m1[1];
    struct s2 m2[1];
  } u;

  (u.m2)->b = 17;
  printf ("%d\n", ((struct s2 *) (struct s1 *) u.m2)->b);
  printf ("%d\n", ((struct s2 *) u.m1)->b);
  return 0;
}

zira:~> gcc-10 tst.c -o tst -O2 -Wstrict-aliasing
tst.c: In function ‘main’:
tst.c:22:20: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
   22 |   printf ("%d\n", ((struct s2 *) u.m1)->b);
      |                   ~^~~~~~~~~~~~~~~~~~~

But there is no type-punning here. All accesses are done via struct s2.
Everything else is pointer conversions, which are not related to the aliasing
rules.

             reply	other threads:[~2020-03-26  2:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26  2:03 vincent-gcc at vinc17 dot net [this message]
2020-03-26  7:03 ` [Bug c/94337] " rguenth at gcc dot gnu.org
2020-03-26  9:12 ` vincent-gcc at vinc17 dot net

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-94337-4@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).