[analyzer] Nullability: allow cast to _Nonnull to suppress warning about returning...
authorDevin Coughlin <dcoughlin@apple.com>
Tue, 29 Dec 2015 17:40:49 +0000 (17:40 +0000)
committerDevin Coughlin <dcoughlin@apple.com>
Tue, 29 Dec 2015 17:40:49 +0000 (17:40 +0000)
commit755baa405065d2264a692467bab5702f83f0c570
tree19f1dd043c8ff95b26573151bdce374d069d8e9c
parent7dd45697ca578874c96d9b938761f8d28d0d525e
[analyzer] Nullability: allow cast to _Nonnull to suppress warning about returning nil.

The nullability checker currently allows casts to suppress warnings when a nil
literal is passed as an argument to a parameter annotated as _Nonnull:

  foo((NSString * _Nonnull)nil); // no-warning

It does so by suppressing the diagnostic when the *type* of the argument expression
is _Nonnull -- even when the symbolic value returned is known to be nil.

This commit updates the nullability checker to similarly honor such casts in the analogous
scenario when nil is returned from a function with a _Nonnull return type:

  return (NSString * _Nonnull)nil; // no-warning

This commit also normalizes variable naming between the parameter and return cases and
adds several tests demonstrating the limitations of this suppression mechanism (such as
when nil is cast to _Nonnull and then stored into a local variable without a nullability
qualifier). These tests are marked with FIXMEs.

rdar://problem/23176782

llvm-svn: 256567
clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
clang/test/Analysis/nullability.mm