]> granicus.if.org Git - clang/commit
[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)
commit87a2f5278ef5b62c4694565df3b4b09b3f249730
tree5f354f65fcac860d634e966dbbdb862b7c0245a8
parent73d6e7e98df34e9e9648d11745c3700bde64a9cd
[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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256567 91177308-0d34-0410-b5e6-96231b3b80d8
lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
test/Analysis/nullability.mm