Scan-build cannot find dead code in cygwin environment

336 Views Asked by At

Following the tutorial here : http://clang-analyzer.llvm.org/scan-build.html and I write a toy example to check whether scan-build can help find the dead code.

The following is the testing code:

#include <stdio.h>
int main () {
    printf("haha this is testing code\n");
    return 0;
    int c = 10;
}

and I run the following in the command-line:

scan-build -v gcc -c test.c

however the scan-build gives the following output:

enter image description here

It does not discover that int c = 10; will not be reached.

Do I miss something?

1

There are 1 best solutions below

0
Max Smolens On

The alpha.deadcode.UnreachableCode checker finds the bug:

Command line:

scan-build -enable-checker alpha.deadcode.UnreachableCode -v gcc -c test.c

Output:

test.c:5:13: warning: This statement is never executed
    int c = 10;
            ^~
1 warning generated.
scan-build: 1 bugs found.

See http://clang-analyzer.llvm.org/alpha_checks.html for more alpha (experimental) checkers.