From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 757F43851176; Thu, 27 Oct 2022 08:39:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 757F43851176 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666859942; bh=BP/u7lAUyiVjjMt4i9a0VHSZbjjsxfcmmLiIE6fQ5Bw=; h=From:To:Subject:Date:From; b=N1JcZwOlNDhVak4alBMOSEi7OAciy7qwUJg/8TvgQmqgZK55VpxSiWxE0A08aqjIw HauIy51ChB+qkoZpNPfIMd3YtPDtfZEpD6nytEAbk5b1dV1JKRKbSjeVYCZVtcuRlV 9Cl6UBTgvx5RojzlOS6p8orTX5HPoQawrauIyR70= From: "shaohua.li at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/107431] New: UBSan has inconsistent behaviors in certain code snippet Date: Thu, 27 Oct 2022 08:39:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: shaohua.li at inf dot ethz.ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: 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=3D107431 Bug ID: 107431 Summary: UBSan has inconsistent behaviors in certain code snippet Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxi= n at gcc dot gnu.org Target Milestone: --- Hi, for the following code, there is a misaligned load at line 5 `long d = =3D *c`. UBSan detected it successfully. However, if you change the definition of `a` from `long a` to `int a`, UBSan would report nothing. % cat example1.c int main() { long a=3D2; int b=3D1; long *c =3D &b; long d =3D *c; &a; } % gcc -O0 -fsanitize=3Dundefined example1.c && ./a.out example1.c:5:10: runtime error: load of misaligned address 0x7fffd97a993c f= or type 'long int', which requires 8 byte alignment 0x7fffd97a993c: note: pointer points here f0 71 77 cc 01 00 00 00 02 00 00 00 00 00 00 00 3c 99 7a d9 ff 7f 00 00= 50 9a 7a d9 ff 7f 00 00 % % cat example2.c int main() { int a=3D2; int b=3D1; long *c =3D &b; long d =3D *c; &a; } % gcc -O0 -fsanitize=3Dundefined example1.c && ./a.out % Compiler explorer: https://godbolt.org/z/4oKaMjbee=