From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 47F17385E015; Thu, 26 Mar 2020 02:03:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47F17385E015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1585188227; bh=uAd0KT+uJmkhHutrPapnmS6Ppgx3s+qu/WN+s91fPZw=; h=From:To:Subject:Date:From; b=PC4uKvU02H1djSjrrY29PU2i7hA6lA0U60B/p3Uoqli9zJ57nsfRxPrfw7yxdCN7h Z5f4fsAxBZV5In6qhJjI5baaRuuy9KjLAG/8/JspwG3pQ1nZHcn7x9zEWX68AmQptL MkmbrhUQ7HyiftDRlQFLzfQZf3XgIss0y3LPsFpI= From: "vincent-gcc at vinc17 dot net" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 02:03:47 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94337 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 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 =3D 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 =E2=80=98main=E2=80=99: 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 aliasi= ng rules.=