[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 15:15:20 PST 2013
This patch makes sure that we do not reinitialize static globals when the function is called more than once along a path. The motivation is code with initialization patterns that rely on 2 static variables, where one of them has an initializer while the other does not. Like the ObjC example below.
Currently, we reset the static variables with initializers on every visit to the function along a path. The solution might be a bit hacky as we check if the region has been stored something other than a LazyCompoundVal to find out if the static variable has been assigned to previously.
Anna.
void Function1(void);
void Function2(void);
NSMutableDictionary * aaa();
void Function1(void)
{
static dispatch_once_t predicate;
static NSMutableDictionary *foo = 0;
if (!predicate) {
predicate = 1;
foo = aaa();
}
@synchronized(foo) {
Function2();
}
}
void Function2(void)
{
// COMMENT OUT THE NEXT LINE TO REMOVE ANALYZER WARNING
Function1();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: staticLocals.diff
Type: application/octet-stream
Size: 2634 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130206/cd5922c4/attachment.obj>
More information about the cfe-commits
mailing list