tripleCC created this revision. Herald added subscribers: steakhal, martong. Herald added a reviewer: NoQ. Herald added a project: All. tripleCC requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D154221 Files: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp clang/test/Analysis/nullability.mm Index: clang/test/Analysis/nullability.mm =================================================================== --- clang/test/Analysis/nullability.mm +++ 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. Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp +++ 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;
Index: clang/test/Analysis/nullability.mm =================================================================== --- clang/test/Analysis/nullability.mm +++ 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. Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp +++ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits