This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix false negative when pass implicit cast nil to nonnull
ClosedPublic

Authored by tripleCC on Jun 30 2023, 7:25 AM.

Details

Summary

We should look through implicit casts before determining the type of the arguments, and only allow explicit cast to _Nonnull to suppress warning

void foo(NSString *_Nonnull);

foo((NSString * _Nonnull)nil); // no-warning
id obj = nil; 
foo(obj); // should warning here (implicit cast id to NSString *_Nonnull)

Diff Detail

Event Timeline

tripleCC created this revision.Jun 30 2023, 7:25 AM
Herald added a project: Restricted Project. · View Herald Transcript
tripleCC requested review of this revision.Jun 30 2023, 7:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 7:25 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tripleCC retitled this revision from Fix false negative when implicit cast nil to nonnull to [analyzer] Fix false negative when implicit cast nil to nonnull.
tripleCC retitled this revision from [analyzer] Fix false negative when implicit cast nil to nonnull to [analyzer] Fix false negative when pass implicit cast nil to nonnull.Jun 30 2023, 7:26 AM
xazax.hun accepted this revision.Jun 30 2023, 7:29 AM
This revision is now accepted and ready to land.Jun 30 2023, 7:29 AM
tripleCC edited the summary of this revision. (Show Details)Jun 30 2023, 7:58 AM
This comment was removed by tripleCC.
steakhal requested changes to this revision.Jul 2 2023, 11:59 PM

The tests are failing on main.
Check the CI bots if they pass on your machine.

This revision now requires changes to proceed.Jul 2 2023, 11:59 PM
tripleCC updated this revision to Diff 537110.Jul 4 2023, 8:07 AM

try to fix nullability-arc.mm test case error

tripleCC added inline comments.Jul 4 2023, 8:18 AM
clang/test/Analysis/nullability-arc.mm
26–27

I'm not sure if this change fixes the issue in D54017 , and may require some further discussion

tripleCC added inline comments.Jul 4 2023, 8:31 AM
clang/test/Analysis/nullability-arc.mm
25–26

I think there should be a warning when we call the foo: method

@tripleCC Could you clarify the status. Do you need some help or review? Do you have concerns?
You made some inline comments that I couldn't put into context.

@tripleCC Could you clarify the status. Do you need some help or review? Do you have concerns?
You made some inline comments that I couldn't put into context.

@steakhal Yes, I need some review, especially concerning the modifications made to file nullability-arc.mm.

If @NoQ could join in the review, that would be even better , as he created this file in D54017.

steakhal accepted this revision.Jul 4 2023, 11:01 PM

I'd say, as tests pass and I and @xazax.hun think that this is an improvement - along with you - then we should merge this as-is and do corrections once reported.

clang/test/Analysis/nullability-arc.mm
25–26

I'm probably a bit naive, but it feels like passing nil to a function that expects _Nonnull seems like a precondition violation no matter if objc-arc is enabled or not. TBH I'm not even sure how that comes into play in this context in the first place.

This revision is now accepted and ready to land.Jul 4 2023, 11:01 PM
This revision was landed with ongoing or failed builds.Jul 6 2023, 7:37 AM
This revision was automatically updated to reflect the committed changes.