Skip to content

Fix a use-after-free in MandatoryInlining #35037

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 1 commit into from
Dec 10, 2020

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Dec 10, 2020

In recordDeadFunction, we look at operands of an instruction to be deleted,
and add back the defining instruction of the operands to the worklist.
This works in general when we are deleting dead instructions
recursively.
But we also consider, an instruction with only debug uses as dead. So
when we are deleting a debug instruction, we may have already deleted
its operand's defining instruction. So it would be incorrect to add it
to the worklist.

Fixes rdar://72029485

@meg-gupta meg-gupta marked this pull request as ready for review December 10, 2020 08:20
@meg-gupta
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

This is good to fix the issue.
Though, I have some comments (you can address them in a follow-up commit if you like).

Also, you should add a test.

@@ -481,6 +481,12 @@ class ClosureCleanup {
if (!operandVal->getType().is<SILFunctionType>())
continue;

// Skip debug instructions
Copy link
Contributor

Choose a reason for hiding this comment

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

This check should be done at the function entry.

Can you add a bit more information in the comment? E.g. Add the info what you wrote in the PR description.
Also, you should mention that the special handling of debug instruction is done in eraseFromParentWithDebugInsts.

In recordDeadFunction, we look at operands of an instruction to be deleted,
and add back the defining instruction of the operands to the worklist.
This works in general when we are deleting dead instructions
recursively.
But we also consider, an instruction with only debug uses as dead. So
when we are deleting a debug instruction, we may have already deleted
its operand's defining instruction. So it would be incorrect to add it
to the worklist.
@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test and merge

@meg-gupta
Copy link
Contributor Author

Thanks @eeckstein . I'll add the test you wrote in a follow on commit.

@swift-ci swift-ci merged commit 723d85b into swiftlang:main Dec 10, 2020
meg-gupta added a commit to meg-gupta/swift that referenced this pull request Dec 11, 2020
ainu-bot added a commit to google/swift that referenced this pull request Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants