From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B99133856252; Wed, 8 Jun 2022 09:35:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B99133856252 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105884] A possible optimization bug when uint64_t is used with -O2/-O3. Date: Wed, 08 Jun 2022 09:35:43 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi 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: resolution bug_status 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 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: Wed, 08 Jun 2022 09:35:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105884 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #2 from Jonathan Wakely --- Definitely an aliasing bug: ((uint64_t*)result->s6_addr)[0] =3D ((uint64_t*)a->s6_addr)[0] & ((uint64_t*)b->s6_addr)[0]; ((uint64_t*)result->s6_addr)[1] =3D ((uint64_t*)a->s6_addr)[1] & ((uint64_t*)b->s6_addr)[1]; Even their "fix" to use uint32_t instead is wrong. With glibc the s6_addr array has type uint8_t[16] so there are no uint64_t = (or uint32_t) objects there. With _GNU_SOURCE or _DEFAULT_SOURCE (formerly _BSD_SOURCE) defined, there i= s a s6_addr32 member which can be used to type-pun the s6_addr array as 32-bit values. The portable solution is to memcpy from s6_addr to uint64_t[2], perform the bitwise AND ops on the uint64_t objects, and then memcpy back to s6_addr.=