[cfe-dev] [analyzer] Simple Example produces an inconsistent result

scott constable via cfe-dev cfe-dev at lists.llvm.org
Mon Nov 2 07:13:22 PST 2015


Hi All,

Given the following code:

// test.cpp
int foo(int len) {
    int j = 0;
    if (len < 10)
        j = 42 / j;
    return j;
}

the command

clang --analyze test.cpp

issues the bug report

tu.cpp:6:10: warning: Division by zero
                j = 42 / j;
                    ~~~^~~

However, it seems that merely introducing another function which calls
foo() with an argument that would not trigger a division by zero nullifies
the bug report. For instance, analyzing

// test.cpp
int foo(int len) {
    int j = 0;
    if (len < 10)
        j = 42 / j;
    return j;
}

void bar() {
    int m = 12;
    foo(m);
}

in the same way will NOT issue a bug report. Isn't this a bug in the static
analyzer?

Note: I tested this with clang 3.7.0 and 3.8.0.

~Scott Constable
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151102/b9b090ce/attachment.html>


More information about the cfe-dev mailing list