-
Notifications
You must be signed in to change notification settings - Fork 12.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][analyzer][NFC] Remove redundant code in StreamChecker #71394
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this alternative less idiomatic (dissimilar to how we implement checks in other checkers), thus I find this less readable.
I'm okay with that amount of redundancy as it was present.
/// Perform some common checks for all preXXX functions. | ||
bool basicCheck(const FnDescription *Desc, const CallEvent &Call, | ||
CheckerContext &C, ProgramStateRef &State, | ||
SVal &StreamVal) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has a role like ensureStreamNonNullAndOpened
, that would be a better name for it. And it should return the new State
, like ensureStreamNonNull
.
return; | ||
State = ensureStreamOpened(StreamVal, C, State); | ||
if (!State) | ||
if (!basicCheck(Desc, Call, C, State, StreamVal)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!basicCheck(Desc, Call, C, State, StreamVal)) | |
State = ensureStreamNonNullAndOpened(Desc, Call, C, State, StreamVal); | |
if (!State) | |
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function returns a state that is modified further by the following functions. Otherwise the state changes applied in basicCheck
are lost. (ensureStreamNonNull
does a state change, ensureStreamOpened
does not, but all return a state to make the usage similar.)
With the current code it is a corner case if this change makes the code more readable. Probably it can be useful if new functions are added to the checker. But the rule here is that there is one "ensure" function to check one aspect of the state, and the pre-callbacks call all of the ensure functions that are needed in that case. It would not much more readable if multiple combinations of ensure functions are made, for example |
It seems my previous change make little sense, so I reuse this PR for another change. |
This change looks not very useful to me. These removed return statements indicate that at the end of the |
How about only remove the second
|
No description provided.