Skip to content

C#: Strengthen call-back heuristics by considering body-less methods #14832

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

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Nov 17, 2023

Previously, we would assume that calls to library methods would invoke their passed delegates. This is now generalized to include any method without a body (i.e., also abstract methods and interface methods).

@github-actions github-actions bot added the C# label Nov 17, 2023
@hvitved hvitved force-pushed the csharp/callback-heuristics branch 5 times, most recently from 302add9 to 393628a Compare November 27, 2023 12:00
@hvitved hvitved force-pushed the csharp/callback-heuristics branch from 393628a to ccb9d9b Compare November 27, 2023 20:30
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Nov 28, 2023
@hvitved hvitved marked this pull request as ready for review November 28, 2023 10:53
@hvitved hvitved requested a review from a team as a code owner November 28, 2023 10:53
Comment on lines 171 to 172
not c.hasBody() and
(if c instanceof AddEventAccessor then not c.fromSource() else any())
Copy link
Contributor

Choose a reason for hiding this comment

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

This same pattern is also used in SsaImpl.qll. Should it be refactored into a predicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code in SsaImpl.qll will go away once we adopt the shared variable capture library, which is expected to happen next quarter.

target = c.getTarget() and
not target.hasBody()
|
if target instanceof AddEventAccessor then not target.fromSource() else any()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to special case AddEventAccessor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because default event accessors will not invoke the callbacks that they are provided, merely add/remove them from the list of callbacks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we need to special case RemoveEventAccessor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, that's definitely a mistake. I think I will simply include all accessors, since the same holds for auto-generated getters/setters.

michaelnebel
michaelnebel previously approved these changes Dec 4, 2023
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

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

LGTM

@hvitved hvitved merged commit 4c8861a into github:main Dec 4, 2023
@hvitved hvitved deleted the csharp/callback-heuristics branch December 4, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants