From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A5ABA3858D39; Mon, 24 Apr 2023 20:30:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5ABA3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682368252; bh=7gOs8Kn8tm/oPJtuU6CpN0rMVNfIljxncNb5wfGSkSo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rhX0Cv63q+sLYy3SZKk8MZg10ChoDYD/mou1p1ND/OXoxDq733KuD4u/j5GGHTH2l RbwxdpNDPSOdXpEvuY1JKjkjYtJFKUdLm+/a1VIoNRE8c92pAgSBWwcAB2wT8Kctw0 iK4HgMwHmNF4dhCcKzFagsdWeaKA0S6YX19wYaQ0= From: "gburca-gnu at ebixio dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109609] [12/13/14 Regression] tail call for function even when passing a ptr which references a local array still Date: Mon, 24 Apr 2023 20:30:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: gburca-gnu at ebixio dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 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=3D109609 --- Comment #7 from Gabriel Burca --- Here's the code that still fails with -O3 -fno-optimize-sibling-calls: ``` #include #include #define N 23 #define MAX_LEN 13 char dst[N + 1]; void stringify(uint64_t id) { char buf[MAX_LEN]; char *ptr =3D buf + sizeof(buf); // start from the end of buf *(--ptr) =3D '\0'; // terminate string while (id && ptr > buf) { *(--ptr) =3D static_cast(id % 10) + '0'; id /=3D 10; } __builtin_strncpy(dst, ptr, N); // copy ptr/buf to dst } int main() { stringify(12345); if (strcmp(dst, "12345")) __builtin_abort(); } ``` Notably this only fails with -O3, not with -O2=