Clang static analyzer: Detect API usage issues with deployment targets

Originator:Karoly.Lorentey
Number:rdar://13705585 Date Originated:22-Apr-2013 05:17 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 4.6.2 (4H1003)
Classification:Enhancement Reproducible:Always
 
Summary:
The Clang Static Analyzer should warn me when I use an API that isn't available on my deployment target but I fail to wrap it in a respondsToSelector: conditional. The analyzer should automatically recognize and accept simple idioms like this:

	if ([foo respondsToSelector:@selector(bar)]) {
		[foo bar]; // 10.8+
	}

It should also be possible to explicitly mark specific calls as OK via some kind of source annotation.

Steps to Reproduce:
Run the Clang static analyzer on the attached project. It deploys to 10.6, but includes unprotected use of the -[NSBundle loadNibNamed:owner:topLevelObjects:] and -[NSAnimationContext runAnimationGroup:completionHandler:] messages.

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSBundle *bundle = [NSBundle mainBundle];
    NSArray *tlo;
    [bundle loadNibNamed:@"Foo" owner:self topLevelObjects:&tlo]; // 10.8
    
    [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { // 10.7
        [context setTimingFunction:nil]; // 10.7
        context.allowsImplicitAnimation = YES; // 10.8
    } completionHandler:^{
    }];
}


Expected Results:
The analyzer should warn me about usages of backward-incompatible API calls that aren't wrapped in respondsToSelector: conditionals.

Actual Results:
No analyzer warnings.

Regression:
None

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!