public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/108935] New: Incorrect warning for infinite recursion
@ 2023-02-26 19:29 zach-gcc at cs dot stanford.edu
  2023-02-27 23:34 ` [Bug analyzer/108935] " dmalcolm at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zach-gcc at cs dot stanford.edu @ 2023-02-26 19:29 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-01 14:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-26 19:29 [Bug analyzer/108935] New: Incorrect warning for infinite recursion zach-gcc at cs dot stanford.edu
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

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).