[Bug analyzer/126834] New: false -Wanalyzer-infinite-recursion in readline/bash: sign-flip mutual recursion termination not tracked

"dmalcolm at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126834

            Bug ID: 126834
           Summary: false -Wanalyzer-infinite-recursion in readline/bash:
                    sign-flip mutual recursion termination not tracked
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
            Blocks: 126830
  Target Milestone: ---

Reduced from readline-8.3 kill.c rl_copy_forward_word/rl_copy_backward_word.

Two functions call each other when count < 0, negating count on each
cross-call.  This mutual recursion always terminates after one step: if count <
0 in copy_forward, it calls copy_backward(-count, key) where -count > 0, so the
guard (count < 0) is false and recursion stops.  The analyzer doesn't track the
sign-flip.

$ cat t.c
extern int do_copy(int count, int direction);
int copy_backward(int count, int key);

int copy_forward(int count, int key)
{
    if (count < 0)
        return copy_backward(-count, key);
    return do_copy(count, 1);
}

int copy_backward(int count, int key)
{
    if (count < 0)
        return copy_forward(-count, key);
    return do_copy(count, -1);
}

$ gcc -O2 -fanalyzer -c t.c
t.c: In function 'copy_forward':
t.c:7:16: warning: infinite recursion [-Wanalyzer-infinite-recursion]
t.c: In function 'copy_backward':
t.c:14:16: warning: infinite recursion [-Wanalyzer-infinite-recursion]

Seen in the August 2026 OpenScanHub mass scan of Fedora 45 (PR 126830)
affecting readline and bash.  Seems to need -O2 or higher.

Trunk: https://godbolt.org/z/srb6dab5x


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126830
[Bug 126830] Tracker bug for -fanalyzer false positives seen in August 2026
OpenScanHub mass scan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.