From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 568E9385842C; Sun, 3 Mar 2024 07:19:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 568E9385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709450369; bh=z3dKG+5uzoqF4vcqQTegPmWB80R1WNfd7Dfy43yQ61k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kdm6EJ/eVfRpsZp6SxiJ1wTW1HB4NO4Eazi6rc+pekUx6AA5w+4YMF7KclPgMDtUD clWUrLDzbilRLCCp6pe2jR4Dyh9pykfM4ygyzwncB/hvDj6ALb/5x086T3swMgCKfs q8E1ycVPpGQFM697gco18BgTqksGM/tj9dZVA5Ek= From: "akihiko.odaki at daynix dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/114217] -fsanitize=alignment false positive with intended unaligned struct member access Date: Sun, 03 Mar 2024 07:19:29 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: akihiko.odaki at daynix dot com 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=3D114217 --- Comment #3 from Akihiko Odaki --- (In reply to Andrew Pinski from comment #1) > >but also emits code to assert alignment. >=20 >=20 > Yes because the code is broken still. >=20 > The alignment is not about when the access happens but rather when the > pointer is casted to. >=20 > So in this case when passing in the argument to f, the argument entry sho= uld > be aligned to what the `struct dir_entry` is aligned to; otherwise it is > undefined code. I had a similar thought when I faced the same issue before and didn't repor= t it then, but this time I realized GCC still emits code to perform slow unalign= ed access for such a construct. Whichever is right, to assume an aligned or unaligned access, it is not consistent. Theoretically, it also makes sense to emit unaligned memory access for such= a construct instead of ignoring it when -fsanitize=3Daddress, but I'm worried= that such a change will break too many things.=