[PATCH] D159549: [analyzer] Fix false negative when accessing a nonnull property from a nullable object
tripleCC via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 27 06:54:07 PDT 2023
tripleCC updated this revision to Diff 557405.
tripleCC added a comment.
adjust return type after checking getOriginExpr is non-null
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D159549/new/
https://reviews.llvm.org/D159549
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
@@ -55,6 +55,7 @@
@property(readonly, nullable) void (^propReturnsNullableBlock)(void);
@property(readonly, nullable) int *propReturnsNullable;
@property(readonly) int *propReturnsUnspecified;
++ (nullable TestObject *)getNullableObject;
@end
TestObject * getUnspecifiedTestObject();
@@ -256,6 +257,12 @@
case 8:
[o takesNonnullBlock:o.propReturnsNullableBlock]; // expected-warning {{Nullable pointer is passed to a callee that requires a non-null 1st parameter}}
break;
+ case 9:
+ [o takesNonnull:getNullableTestObject().propReturnsNonnull]; // expected-warning {{Nullable pointer is passed to a callee that requires a non-null 1st parameter}}
+ break;
+ case 10:
+ [o takesNonnull:[TestObject getNullableObject].propReturnsNonnull]; // expected-warning {{Nullable pointer is passed to a callee that requires a non-null 1st parameter}}
+ break;
}
}
Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -899,6 +899,9 @@
const NullabilityState *TrackedNullability =
State->get<NullabilityMap>(Region);
+ if (const Expr *E = Call.getOriginExpr())
+ ReturnType = E->getType();
+
if (!TrackedNullability &&
getNullabilityAnnotation(ReturnType) == Nullability::Nullable) {
State = State->set<NullabilityMap>(Region, Nullability::Nullable);
@@ -1053,7 +1056,7 @@
}
// No tracked information. Use static type information for return value.
- Nullability RetNullability = getNullabilityAnnotation(RetType);
+ Nullability RetNullability = getNullabilityAnnotation(Message->getType());
// Properties might be computed, which means the property value could
// theoretically change between calls even in commonly-observed cases like
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159549.557405.patch
Type: text/x-patch
Size: 2103 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230927/609cb6db/attachment.bin>
More information about the cfe-commits
mailing list