]> granicus.if.org Git - clang/commit
[analyzer] ObjCGenerics: Warn only on mismatch for invariant type parameters
authorDevin Coughlin <dcoughlin@apple.com>
Mon, 5 Dec 2016 16:28:47 +0000 (16:28 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Mon, 5 Dec 2016 16:28:47 +0000 (16:28 +0000)
commitc40a10d07a6dd296afc88c7facd401915210b622
treeb1097bf73448b38d989d527ddf7bed8041fac8fc
parent96d53fef2346ea7001801462ad338c7f01197d19
[analyzer] ObjCGenerics: Warn only on mismatch for invariant type parameters

On a method call, the ObjCGenerics checker uses the type tracked by
DynamicTypePropagation for the receiver to to infer substituted parmeter types
for the called methods and warns when the argument type does not match the
parameter.

Unfortunately, using the tracked type can result in false positives when the
receiver has a non-invariant type parameter and has been intentionally upcast.
For example, becaue NSArray's type parameter is covaraint, the following code
is perfectly safe:

NSArray<NSString *> *allStrings = ...
NSDate *date = ...;
NSArray<NSObject *> *allObjects = allStrings;
NSArray<NSObject *> *moreObjects = [allObjects arrayByAddingObject:date];

but the checker currently warns that the date parameter is not an NSString *.

To avoid this kind of false positive, the checker will now only warn when
the class defining the called method has only invariant type parameters.

rdar://problem/28803951

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288677 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
test/Analysis/generics.m