From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 987713858C56; Mon, 4 Mar 2024 08:45:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 987713858C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709541958; bh=4oTJzjBQds8C5cU7nf82sRGc/A/QiTB0As9lfOJN8U8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ogYorixEeuNt+OQ8JTD0twR3Ug2zOr/GWfimbDrcBq3oAJU28XUheCMCsNIqt5bdV Apnl+KvTPX3sIoQO6/0mnYjhj8rD20rZIkwdpJwYDk21Zdyjnlm+xr+Q0ygm2f+LtU YtcrNYy5tt67mC6y4elV1Dmmterci/KES8j2Udv4= 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: Mon, 04 Mar 2024 08:45:57 +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 #13 from Akihiko Odaki --- (In reply to Jakub Jelinek from comment #12) > (In reply to Akihiko Odaki from comment #11) > > So there are two constructs invoking UBs but ignored by UBSan: 1) >=20 > That is an understatement. UBSan is a best effort which diagnoses some fo= rms > of undefined behavior. There are tons of undefined behavior UBSan doesn't > catch, > most importantly e.g. aliasing violations, but far from limited to just t= hat. > If a program is diagnostic free with -fsanitize=3Dundefined,address , it > doesn't mean it is UB free, but the goal is that if there is diagnostic, > there is a real UB in the program. Right. I just listed the two relevant constructs and don't intend to say th= ey are the only case that UBSan doesn't catch. >=20 > You are basically asking for the PR80797 fix to be reverted just because = you > aren't willing to fix UB in your code. That is not going to happen, we've > been diagnosing this for almost 7 years now, I think clang even for 11 > years, it is a real UB and other projects have been able to cope with it.= =20 > By reverting the change new UB in other programs couldn't be discovered. I'm not asking for reverting PR80797. See f() and f2() I wrote earlier: u64 f(struct dir_entry *entry) { return get_unaligned(&entry->offset); } u64 f2(u64 *offset) { return get_unaligned(offset); } Both f(NULL) and f2(NULL) should be caught and there should be no discrepan= cy in behavior for these two functions. However, there is a discrepancy when it comes to -fsanitize=3Dalignment. I'm not saying ignoring UB in f() is the only sensible option either. Catch= ing UBs in both f() and f2() is a logical option.=