diff --git a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp @@ -767,7 +767,7 @@ Nullability RequiredNullability = getNullabilityAnnotation(Param->getType()); Nullability ArgExprTypeLevelNullability = - getNullabilityAnnotation(ArgExpr->getType()); + getNullabilityAnnotation(lookThroughImplicitCasts(ArgExpr)->getType()); unsigned ParamIdx = Param->getFunctionScopeIndex() + 1; diff --git a/clang/test/Analysis/nullability.mm b/clang/test/Analysis/nullability.mm --- a/clang/test/Analysis/nullability.mm +++ b/clang/test/Analysis/nullability.mm @@ -69,6 +69,7 @@ void takesNonnull(Dummy *_Nonnull); void takesUnspecified(Dummy *); void takesNonnullBlock(void (^ _Nonnull)(void)); +void takesNonnullObject(TestObject *_Nonnull); Dummy *_Nullable returnsNullable(); Dummy *_Nonnull returnsNonnull(); @@ -264,6 +265,11 @@ return (Dummy * _Nonnull)0; // no-warning } +void testImplicitCastNilToNonnull() { + id obj = nil; + takesNonnullObject(obj); // expected-warning {{nil passed to a callee that requires a non-null 1st parameter}} +} + void testIndirectCastNilToNonnullAndPass() { Dummy *p = (Dummy * _Nonnull)0; // FIXME: Ideally the cast above would suppress this warning.