-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Refactor some side effect generation code #5643
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
C++: Refactor some side effect generation code #5643
Conversation
This change was necessary for my upcoming changes to introduce side effect instructions for indirections of smart pointers. The code to decide which parameters have which side effects appeared in both the IPA constructor for `TTranslatedSideEffect` and in `TranslatedCall`. These two versions didn't quite agree, especially once the `SideEffectFunction` model provides its own side effects instead of the defaults. The relevant code has now been factored out into `SideEffects.qll`. This queries the model if one exists, and provides default side effects if no model exists. This fixes at least one existing issue, where we were emitting a buffer read side effect for `*this` instead of an indirect read side effect. This accounts for all of the IR diffs in the tests.
rdmarsh2
left a comment
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.
IR generation changes look good to me, with a couple nitpicks. Once the field flow tests are fixed, those changes should probably be reviewed by @MathiasVP
cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll
Show resolved
Hide resolved
cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll
Outdated
Show resolved
Hide resolved
We have special code to handle field flow for single-field structs, but that special case was too specific. Some `Store`s to single-field structs have no `Chi` instruction, which is the case that we handled already. However, it is possible for the `Store` to have a `Chi` instruction (e.g. for `{AllAliased}`), but still have a use of the result of the `Store` directly. We now add a `PostUpdateNode` for the result of the `Store` itself in those cases, just like we already did if the `Store` had no `Chi`.
|
@MathiasVP I've added another commit to fix the broken dataflow tests. Hopefully the comment in the commit and in the code describes the change well enough. |
Commit 697b2dc LGTM (except for formatting). |
|
LGTM once formatting is fixed. |
This change was necessary for my upcoming changes to introduce side effect instructions for indirections of smart pointers. The code to decide which parameters have which side effects appeared in both the IPA constructor for
TTranslatedSideEffectand inTranslatedCall. These two versions didn't quite agree, especially once theSideEffectFunctionmodel provides its own side effects instead of the defaults.The relevant code has now been factored out into
SideEffects.qll. This queries the model if one exists, and provides default side effects if no model exists. This fixes at least one existing issue, where we were emitting a buffer read side effect for*thisinstead of an indirect read side effect. This accounts for all of the IR diffs in the tests.