[cfe-dev] Static analyzer gives no warnings in #included *.c files

Ted Kremenek kremenek at apple.com
Mon Jan 23 16:22:26 PST 2012


This is a heuristic.  The idea is that code included from headers should not be analyzed since it is repeatedly included.  This heuristic is not optimal, and certainly could be relaxed for included files that are not headers.  Moreover, we are experimenting with basic IPA, and if a function within the header is called by code within the main source file then that code will be analyzed in that case.

For this specific case, I think it is worth filing a PR.

On Jan 23, 2012, at 2:06 PM, Robert Purves wrote:

> Ping.
> Is this by design or a bug?
> 
> 
>> $ cat foo.c
>> int foo( void ) { 
>>   int x;
>>   if ( x ) return 1; /* uninitialized */
>>   return 0;
>> }
>> 
>> $ cat main.c
>> #include "foo.c" /* ignored by static analyzer? */
>> int main( void ) { 
>>   return 0;
>> }
>> 
>> $ clang main.c --analyze
>> $ clang --version
>> clang version 3.1 (trunk 148340)
>> 
>> 
>> Analysis of main.c is defective. Explicit analysis of foo.c does give a warning.
>> 
>> $ clang foo.c --analyze
>> foo.c:3:10: warning: Branch condition evaluates to a garbage value
>>   if ( x ) return 1; /* uninitialized */
>>        ^
>> 1 warning generated.
> 
> Robert P.
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list