[cfe-dev] new -Wuninitialized implementation in Clang

Henry Mason thefridgeowl at gmail.com
Fri Feb 4 09:24:30 PST 2011


On Feb 4, 2011, at 6:02 AM, Michael Price - Dev wrote:

> On Feb 4, 2011, at 12:32 AM, "John N. Lehner" <jlehner at apple.com> wrote:
> 
>> On Feb 3, 2011, at 8:27 PM, Johannes Schaub (litb) wrote:
>> <snip>
>> 
>> int x = 0;
>> ...
>> if (flag)
>> x = ...
>> ...
>> if (flag)
>> use(x);
>> ...
>> use(x);
>> 
>> and use(0) is wrong.  While that may seem contrived, I saw it happen  
>> in a loop once, and use(0) turned out to be expensive.
> 
> I strongly disagree. How can use(0); be worse than use(garbage that  
> can potentially be zero or that can potentially crash your app causing  
> data corruption);

Obviously having non-deterministic behavior like that is bad. However, when you declare x uninitialized, the static analyzer *can* correctly determine that the first use(x) is valid while the second one is not. It would really suck to make our smart analysis less effective because everyone is structuring their code to please the dumb analysis.

I suppose for those willing to eat the performance cost, you could just compile without -Wunintialized and always uses the static analyzer's uninitialized checker.

-Henry





More information about the cfe-dev mailing list