[PATCH] [analyzer] Do not reinitialize static globals when the function is called more than once along a path

Ted Kremenek kremenek at apple.com
Wed Feb 6 23:57:26 PST 2013


On Feb 6, 2013, at 4:41 PM, Anna Zaks <ganna at apple.com> wrote:

>> $ cat t.mm
>> #include <stdio.h>
>> 
>> id foo(id x) {
>>   printf("%p\n", x);
>>   return x;
>> }
>> 
>> int main() {
>>   static id x = foo(x);
>> }
>> 
> 
> What are the semantics in this case? Would the value be uninitialized or 0?
> 

I believe the compiler zero-initializes 'x' before the initializer runs.  That's why the call to foo() prints out 0x0.  foo() could have returned a different pointer of course, and that is what gets stored to 'x' after running the initializer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130206/5e466ae1/attachment.html>


More information about the cfe-commits mailing list