Skip to content

Conversation

@benshi001
Copy link
Member

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Nov 6, 2023
Copy link
Contributor

@steakhal steakhal left a 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.

Copy link
Collaborator

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!basicCheck(Desc, Call, C, State, StreamVal))
State = ensureStreamNonNullAndOpened(Desc, Call, C, State, StreamVal);
if (!State)
return;

Copy link
Collaborator

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.)

@balazske
Copy link
Collaborator

balazske commented Nov 6, 2023

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 ensureStreamNonNullAndOpenedAndNoFilePositionIndeterminate.

@benshi001 benshi001 changed the title [clang][Analyzer][NFC] Simplify preDefault/preFseek/preFreadFwrite of StreamChecker [clang][analyzer][NFC] Remove redundant code in StreamChecker Nov 7, 2023
@benshi001
Copy link
Member Author

It seems my previous change make little sense, so I reuse this PR for another change.

@balazske
Copy link
Collaborator

balazske commented Nov 7, 2023

This change looks not very useful to me. These removed return statements indicate that at the end of the if branch there is no more work to do in this function, and it reduces complexity (less execution paths). The code becomes a bit shorter but not necessarily more easy to understand. Optimizing code for execution speed or binary size is not important because I am sure that compiler optimizations can handle this case.

@benshi001
Copy link
Member Author

How about only remove the second return State ? The removal of the first one may be less readable. But for the second one, it is very near to the final return State. It may looks strange for very near return States.

if () {
   return State;
}
return State;

@benshi001 benshi001 merged commit 1b45fe5 into llvm:main Nov 7, 2023
@benshi001 benshi001 deleted the csa-nfc branch November 7, 2023 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:static analyzer clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants