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

Anna Zaks ganna at apple.com
Wed Feb 6 16:41:11 PST 2013


On Feb 6, 2013, at 3:27 PM, Ted Kremenek <kremenek at apple.com> wrote:

> On Feb 6, 2013, at 3:24 PM, Ted Kremenek <kremenek at apple.com> wrote:
> 
>> Put another way, this patch seems to rely on the value of a variable being "uninitialized" to indicate whether or not the initializer has been executed.  That's not a valid assumption.  For example:
>> 
>>   static id x = foo(x);
>> 
>> is "okay" in Objective-C.
> 
> … or rather Objective-C++.
> 
> $ 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?

> $ clang++ t.mm
> $ ./a.out
> 0x0

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130206/cbe54bca/attachment.html>


More information about the cfe-commits mailing list