From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CBB2A3858D35; Tue, 17 Jan 2023 21:51:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBB2A3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673992273; bh=0oi19helTpenKm3btR2lWq3m7ztss6q/USxxuQ/uTyE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VcFdbQL5JF0NORgwgP7AgK267g4RDAl87fVU/+SE7sqKmPEANtL9RC0jWxay3kzy1 /IgaDjyMua29hhlep1WhX7oGKahMFCoqTR+9Pm1y/pv3PmN+0vLhe2BDIB4yS8wJhS ebGfmy3oX45Szv86XsTLrDVA2hnesTTevtcBZY6Q= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108439] incorrect optimization with -O2, -O3, -Os Date: Tue, 17 Jan 2023 21:51:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108439 --- Comment #6 from Andrew Pinski --- Aliasing rules are NOT a local thing and they are not about what the type of the pointer is, rather than they are about the access after the casting. Th= ey are also global ... GCC used to have strict aliasing warnings which might warn during optimizat= ions but it had many false positives so it was tuned down a lot. The rules are simple in most cases (there are complex parts to it when deal= ing with unions and structures but more complex in the implementation of the compiler). Some reading on this subject: https://developers.redhat.com/blog/2020/06/02/the-joys-and-perils-of-c-and-= c-aliasing-part-1 https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8 There are many more papers about C/C++ aliasing rules if you want to go rea= d up on why GCC is doing the "correct" thing here.=