facebook / infer

A static analyzer for Java, C, C++, and Objective-C
http://fbinfer.com/
MIT License
14.79k stars 2k forks source link

Can Infer spot dead code in C? #1837

Closed u201111476 closed 1 month ago

u201111476 commented 1 month ago

I have a file named main.c,whose content is as following:

#include <stdio.h>
int main()
{
if(false)
{
printf("skip!\n");
}
return 0;
}

then I use infer capture -- clang -c main.c and infer analyze,there is no dead code in the result though the printf will never execute. What should I do to let Infer report this dead code?

skcho commented 1 month ago

Infer detects dead store, but not general dead code as above. In addition, the liveness checker does simple data flow analysis, so does not try to understand the boolean condition that is always evaluated to true or false. https://fbinfer.com/docs/next/all-issue-types#dead_store

u201111476 commented 4 weeks ago

Does Infer plan to release a next version to support dead code check?