From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 863423858C50; Fri, 21 Apr 2023 10:39:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 863423858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682073561; bh=I1Iije4XA08PAmxyJ9oi2xPJrmxUpdAKK7QjpcfcDH4=; h=From:To:Subject:Date:From; b=nmbRHVUkwtFm+OylkyNWRySrnsCJKOHqQO8tkSyYv3kNvOFFO3kaROLC3uHAx+939 fFN0g6KlE8vv6DFkyUsTC6Nj0P0p3XqvmbKdnGHLup1R00YJHEJMcosaFYVzTAtUkh eIwROsvtivmyM4QfA2OGr7q4PamxLEJoSNuJeSM0= From: "hector at marcansoft dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/109585] New: Carla/sord miscompiled with -O2 on ARM64 (inlining issue) Date: Fri, 21 Apr 2023 10:39:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hector at marcansoft dot com 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 target_milestone attachments.created 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=3D109585 Bug ID: 109585 Summary: Carla/sord miscompiled with -O2 on ARM64 (inlining issue) Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: hector at marcansoft dot com Target Milestone: --- Created attachment 54900 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54900&action=3Dedit Manually annotated disassembly identifying the problem GCC 12.1.0 miscompiles sord_free() with -O2 due to bad inlining on ARM64. Reproducible on Compiler Explorer on 12.2 and also trunk. https://godbolt.org/z/rvxP1oodh (includes full preprocessed input) I've attached an annotated disassembly. The problem is that zix_btree_iter_increment() and zix_btree_iter_is_end() are inlined together into sord_free(), but the `i->stack[0].node =3D=3D NULL` check in zix_btree_iter_is_end() somehow got hoisted before the `f->node =3D NULL;` = in zix_btree_iter_increment(), so the check fails when it pass (ending the loo= p), and then the loop body goes on to deref a NULL pointer.=