From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EDC023858D32; Sun, 26 Feb 2023 19:29:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDC023858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677439798; bh=83HG8fCz1PAWXYt0fdpOR3hzxHICEdzpST87hNe9xdY=; h=From:To:Subject:Date:From; b=xGsZegz8AQw6p9z7wljg0uycbpRMHD165cl5XbCMAydFjp0O7ZrphysJgG20rBT+F qqMeDlVu20P34XYyJjLkvaCEC3XydeoprDJH9ibOVQotRqf8n5ME+8gar5mIXwaEik /TxHDVzfUpauhIvwNT+Z/VjD8rNKHD2P2XcBaOYU= From: "zach-gcc at cs dot stanford.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug analyzer/108935] New: Incorrect warning for infinite recursion Date: Sun, 26 Feb 2023 19:29:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: analyzer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: zach-gcc at cs dot stanford.edu X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: dmalcolm 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 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=3D108935 Bug ID: 108935 Summary: Incorrect warning for infinite recursion Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: zach-gcc at cs dot stanford.edu Target Milestone: --- The following code does not have infinite recursion: ``` typedef struct { unsigned idx; int vals[512]; } foo_t; int ended(foo_t* f) { return f->idx >=3D 512; } unsigned foo(foo_t* f) { if (ended(f)) { return f->idx; } do { f->idx++; } while(!ended(f) && !f->vals[f->idx]); return foo(f); } ``` but -fanalyzer reports infinite recursion (called with `gcc -fanalyzer -c test.c`). The function always makes progress towards f->idx reaching 512, w= hich is the termination condition. It is bounded to at most 512 recursive calls.= I can even add `f->idx +=3D 1000` and the warning is still reported. I've also noticed the following example causes a similar warning, but only = when `foo` is also invoked. ``` typedef struct { unsigned done; } foo_t; unsigned foo(foo_t* f) { if (f->done) { return f->done; } f->done =3D 1; return foo(f); } int main() { foo_t f =3D (foo_t){ .done =3D 0, }; // must be called to cause warning foo(&f); } ``` Tested on version GCC 13 20230203 (commit hash a37a0cb303d). Thanks.=