https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94851

--- Comment #5 from Hugo Gualandi <hugo_musso_gualandi at hotmail dot com> ---
Hi, I came across a similar problem and I think I might have found a smaller
test case. gcc complains about a NULL pointer dereference in the p->next
despite the loop condition testing that p is not NULL.

The first test case I attached only hits the bug if we compile with -O1. The
second test case hits the bug both in -O1 and -O2.

    gcc -O1 -fanalyzer bug-O1 -o bug-O1
    gcc -O1 -fanalyzer bug-O2 -o bug-O2

The problem goes away if I refactor the code to not use the && operator

    while (p) {
        if (p == q) break;
        p = p->next;
    }

I tested with the version of GCC 10.0.1 present in Fedora 32 and with GCC
10.1.0, which I built from source.

Reply via email to