This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix false negative when using a nullable parameter directly without binding to a variable
ClosedPublic

Authored by tripleCC on Jun 15 2023, 6:29 AM.

Details

Summary

If a parameter has a nullability annotation, the nullability information of the parameter should be set as a NullabilityState trait at the beginning of the function.
I don't have commit access.

Diff Detail

Event Timeline

tripleCC created this revision.Jun 15 2023, 6:29 AM
Herald added a project: Restricted Project. · View Herald Transcript
tripleCC requested review of this revision.Jun 15 2023, 6:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2023, 6:29 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tripleCC edited the summary of this revision. (Show Details)Jun 15 2023, 6:36 AM
tripleCC added a reviewer: steakhal.
tripleCC edited the summary of this revision. (Show Details)

I believe, zaks.anna and vsavchenko are no longer involved in the project.
I think it makes sense to have the code owners NoQ and xazax.hun as reviewers, and I also tend to review quite a lot nowadays.
And we usually use the [analyzer] tag instead of [StaticAnalyzer] for the patches.
It's useful to use the right tags to trigger the right herald scripts to get the right circle notified.

clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
569–573

Shouldn't we only do this for the analysis entrypoints only? (aka. top-level functions)
I assume this checker already did some modeling of the attributes, hence we have the warnings in the tests.

569–594

Uh, the diffing here looks terrible.
What you probably want: Fold the States, and if you are done, transition - but only if we have any parameters.
We need to have a single addTransition() call if we want a single execution path modeled in the graph. We probably don't want one path on which the first parameter's annotation is known; and a separate one where only the second, etc.

tripleCC retitled this revision from [StaticAnalyzer] Fix false negative when using a nullable parameter directly without binding to a variable to [analyzer] Fix false negative when using a nullable parameter directly without binding to a variable.Jun 15 2023, 7:54 AM
tripleCC updated this revision to Diff 531779.Jun 15 2023, 8:47 AM

add inTopFrame condition. call the addTransition function only once for all params.

steakhal added inline comments.Jun 15 2023, 8:58 AM
clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
569–594

Please note that each iteration of the loop will overwrite the state you made in the previous iteration this way.
Its most likely not what you want.
Because C.getState() will always return the same state no matter the context here.

tripleCC added inline comments.Jun 15 2023, 9:00 AM
clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
569–573

Thanking for your reviewing. You are correct, I added an inTopFrame() condition here. It only makes sense for top-level functions.

569–594

I made a rookie mistake here. I should call the addTransition function outside the for loop.

tripleCC updated this revision to Diff 531784.Jun 15 2023, 9:04 AM

Do not overwrite state

tripleCC added inline comments.Jun 15 2023, 9:13 AM
clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
569–594

Updated

Now it looks much better. Let me check it in depth tomorrow.

steakhal accepted this revision.Jun 16 2023, 8:33 AM

LGTM; I'll commit this on Monday.

This revision is now accepted and ready to land.Jun 16 2023, 8:33 AM
xazax.hun accepted this revision.Jun 16 2023, 8:57 AM
tripleCC marked an inline comment as done.EditedJul 1 2023, 9:55 PM

LGTM; I'll commit this on Monday.

Hi steakhal, sorry to bother you again. Do you mind committing the revision for me ?

LGTM; I'll commit this on Monday.

Oops, It seems that I missed the invitation, I just noticed the invitation email in my gmail now ...
I will request Chris to send the invitation again.
Thank you for your recommendation.