[cfe-dev] Clang Static Analyzer does not show all bugs in function

Alexander Zaitsev via cfe-dev cfe-dev at lists.llvm.org
Sun Sep 30 18:03:08 PDT 2018


Hello.

I am testing Clang Static Analyzer (CSA) on this code sample:


int main()
{
    int* c = new int[10];
    free(c);

    int* d = new int;
    free(d);

    int* e = (int*)malloc(10);
    delete e;
}


For testing I have built clang from trunk and run analysis as
'./scan-build -k --use-analyzer=clang ./clang++ main.cpp'. Then I get
only one report about first bug:


 main.cpp:11:14: warning: Memory allocated by 'new[]' should be
deallocated by 'delete[]', not free()
    free(c);
    ^~~~~~~
1 warning generated.
scan-build: 1 bug found.


No information about errors on the next lines. When I comment first two
lines with bug, CSA is able to find next bug and so on.

Is there any workaround for this? Is it a bug? (at least for me for now
it looks like a bug)




More information about the cfe-dev mailing list