public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "zach-gcc at cs dot stanford.edu" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-108935-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108935 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 >= 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, which is the termination condition. It is bounded to at most 512 recursive calls. I can even add `f->idx += 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 = 1; return foo(f); } int main() { foo_t f = (foo_t){ .done = 0, }; // must be called to cause warning foo(&f); } ``` Tested on version GCC 13 20230203 (commit hash a37a0cb303d). Thanks.
next reply other threads:[~2023-02-26 19:29 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-26 19:29 zach-gcc at cs dot stanford.edu [this message] 2023-02-27 23:34 ` [Bug analyzer/108935] " dmalcolm at gcc dot gnu.org 2023-03-01 13:57 ` cvs-commit at gcc dot gnu.org 2023-03-01 14:15 ` dmalcolm at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108935-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).