Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang Static Analyzer doesn't find the most basic problems

I wanted to try out the clang static analyzer. I'm on Windows and built clang with Visual Studio. It seems to work, but at the same time it seems to be extremely useless.

I made an example file

example.c

int main(void) 
{
    int h = 0;
    return 1/h;
}

Calling scan-build gcc -c example.c finds no error.

example.c

int main(void) 
{
    int h;
    return 1/h;
}

Calling scan-build gcc -c example.c finds no error.

example.c

int main(void) 
{
    return 1/0;
}

Calling scan-build gcc -c example.c finds no error.

If these most basic errors can't be found (and they can be found by clang itself), how can the static analyzer be of any use?

My gcc is MinGW if that matters. I also tried substituting clang but there's just nothing happening.

Am I doing something wrong here?

like image 295
CodeMonkey Avatar asked Mar 09 '17 13:03

CodeMonkey


Video Answer


1 Answers

be sure to use build-scan -v (verbose) to see if actually running clang checker. I followed this tutorial http://web.cs.ucla.edu/~tianyi.zhang/tutorial.html When I tried the C++ example it did not show any errors in the buggy code. The -v showed me that the provided Makefile was broken - after I fixed that clang still did not detect the bugs but g++ shows the bug.

Maybe they turned that particular check off. Clang Static Analyzer version 3.8 The tutorial uses version 3.2

like image 190
MarkT Avatar answered Oct 30 '22 05:10

MarkT