From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 698223889E32; Thu, 27 Oct 2022 08:48:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 698223889E32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666860526; bh=e85L3FNbkWmin7VwJaqlUskHGeGgXIT0J461DquqAKU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GiNyU6VQk1/miOZiy0JIuBMs+VfoehpvMpU5JoYhQbU+hlNL6Rwcj63I8tyccVcW2 5anXGkwQpJACsGRteokIT99BuXPt1ZbNVrvNp41lB0JSP5hxbA7CCMdkAI7pZod+o2 hcWy/QNYPiUv0F0fjqNX3nFsND5KhtTLO3r7gmpk= From: "marxin at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/107431] UBSan has inconsistent behaviors in certain code snippet Date: Thu, 27 Oct 2022 08:48:46 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: marxin 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: bug_status resolution 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=3D107431 Martin Li=C5=A1ka changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Martin Li=C5=A1ka --- > % cat example2.c > int main() { > int a=3D2; > int b=3D1; > long *c =3D &b; > long d =3D *c; > &a; > } Well, in this case you are lucky and 'b' is aligned to 8-bytes: __builtin_printf ("&b=3D%p\n", &b); $ gcc-12 example2.c -fsanitize=3Dundefined -w && ./a.out &b=3D0x7fffffffd438 $ gcc-12 -O1 example2.c -fsanitize=3Dundefined -w && ./a.out &b=3D0x7fffffffd44c example2.c:6:10: runtime error: load of misaligned address 0x7fffffffd44c f= or type 'long int', which requires 8 byte alignment 0x7fffffffd44c: note: pointer points here 67 6c 69 62 01 00 00 00 68 d5 ff ff ff 7f 00 00 b0 c5 62 f7 ff 7f 00 00= 50 d5 ff ff ff 7f 00 00 ^=20 example2.c:6:10: runtime error: load of address 0x7fffffffd44c with insufficient space for an object of type 'int' 0x7fffffffd44c: note: pointer points here 67 6c 69 62 01 00 00 00 68 d5 ff ff ff 7f 00 00 b0 c5 62 f7 ff 7f 00 00= 50 d5 ff ff ff 7f 00 00 ^=20 So nothing we can do about it.=