From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6A0F13858C41; Wed, 19 Jun 2024 22:13:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A0F13858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718835193; bh=YSjCFc61eb1TP3YfZDp5u8u8SlYilYcEr/QpY2kzJ1U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=m91ACUs4Wk3UFZCrL0KZbp1p2u44gAz5BowBdtuFZi8xNGfUdvs3RtvK01Yfsn4h3 5eXd/xp0oeXXremvYXX+37aFMsVHZbLaT9M5/zAk9cF1sbIsZbBrFRD8nhEhMJrbfe 4DdCi7d6B4jf2Y6Us1kW7r3xJnfzeL+JQO9n85PA= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/115552] wrong code at -O2 and above when strict-aliasing with uint128 and double Date: Wed, 19 Jun 2024 22:13: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.0 X-Bugzilla-Keywords: alias, wrong-code 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=3D115552 --- Comment #2 from Andrew Pinski --- So basically since main writes via a double type but then spookyhash_short reads via a uint64_t type there is an alias violation. Using an union to change the pointer type does not change there is an alias violation happening. You need to use memcpy for copying from one type to another in this case.=20 Instead of doing: c +=3D u.p64[0]; You could do load_64(&u.p64[0]) and have load_64 defined to be: ``` static inline uint64_t load_64(void *a) { uint64_t t; memcpy(&t, a, sizeof(t)); return t; } ```=