This patch uses castAs instead of getAs which will assert if the type doesn't match and directly uses ReceiverType->castAs<ObjCObjectPointerType>() instead of ReceiverObjectPtrType when calling canAssignObjCInterfaces() in findMethodDecl(clang::ObjCMessageExpr const *, clang::ObjCObjectPointerType const *, clang::ASTContext &).
Details
Diff Detail
Event Timeline
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp | ||
---|---|---|
754–755 | We are assigning: ReceiverObjectPtrType = nullptr return value from getAs. const auto *ReceiverObjectPtrType = ReceiverType->getAs<ObjCObjectPointerType>(); Then we are dereferencing nullptr ReceiverObjectPtrType when calling canAssignObjCInterfaces() |
clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp | ||
---|---|---|
754–755 | This isn't NFC, as ReceiverObjectPtrType is only used here. If the MessageExpr ReceiverKind is not Instance or Class, we never dereference this. So the declaration should be in this branch. | |
754–755 | Oh, and ALSO, we don't dereference it if ReceiverType is ObjCIdType or ObhjCClassType. |
I agree with @erichkeane.
However, I can also see that the code could be improved.
I don't understand why we have that variable hoisted from the guarded block in the first place.
We could directly use ReceiverType->castAs<ObjCObjectPointerType>() instead of ReceiverObjectPtrType.
Thank you @erichkeane and @steakhal for reviews and feedbacks. I have updated patch to address your review comments.
Please update the title and the summary of this patch to reflect what it actually achieves.
We also usually use the [analyzer] tag only for changes touching StaticAnalyzer stuff.
After these, you can merge the patch.
Thanks for refactoring the to express the intent more clearly.
Thank you @erichkeane and @steakhal for reviews and comments.
Yes, i will update the title and summary of this patch before merging the patch.
We are assigning: ReceiverObjectPtrType = nullptr return value from getAs.
Then we are dereferencing nullptr ReceiverObjectPtrType when calling canAssignObjCInterfaces()