Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,14 @@ void NullabilityChecker::checkPostCall(const CallEvent &Call,
const NullabilityState *TrackedNullability =
State->get<NullabilityMap>(Region);

// ObjCMessageExpr gets the actual type through
// Sema::getMessageSendResultType, instead of using the return type of
// MethodDecl directly. The final type is generated by considering the
// nullability of receiver and MethodDecl together. Thus, The type of
// ObjCMessageExpr is prefer.
if (const Expr *E = Call.getOriginExpr())
ReturnType = E->getType();

if (!TrackedNullability &&
getNullabilityAnnotation(ReturnType) == Nullability::Nullable) {
State = State->set<NullabilityMap>(Region, Nullability::Nullable);
Expand Down Expand Up @@ -1053,7 +1061,7 @@ void NullabilityChecker::checkPostObjCMessage(const ObjCMethodCall &M,
}

// 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
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Analysis/nullability.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ - (void)takesUnspecified:(int *)p;
@property(readonly, nullable) void (^propReturnsNullableBlock)(void);
@property(readonly, nullable) int *propReturnsNullable;
@property(readonly) int *propReturnsUnspecified;
+ (nullable TestObject *)getNullableObject;
@end

TestObject * getUnspecifiedTestObject();
Expand Down Expand Up @@ -256,6 +257,12 @@ void testObjCPropertyReadNullability() {
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;
}
}

Expand Down