Skip to content

[sil-opt] Fix covering all-case of trapping instruction of SILInstruction::mayTrap #33851

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
Sep 13, 2020
Merged

[sil-opt] Fix covering all-case of trapping instruction of SILInstruction::mayTrap #33851

merged 2 commits into from
Sep 13, 2020

Conversation

freddi-kit
Copy link
Contributor

@freddi-kit freddi-kit commented Sep 8, 2020

Hi, I found that the function which checking trapping SIL instruction may have an issue, so I want to fix by this PR.
(moved from #33830 to fix commit comment)

Abstract

Making SILInstruction:: mayTrap covering all cases of trapping instruction.

Issue

Having no issue-report

Description

It seems that SILInstruction::mayTrap() is checking that the instruction may trap or not.

And, according to the sil.rst, there are 4 instruction may trap (runtime-failure).

  • cond_fail
  • unconditional_checked_cast
  • unconditional_checked_cast_addr
  • unconditional_checked_cast_value

ref: https://github.com/apple/swift/blob/master/docs/SIL.rst#cond_fail and https://github.com/apple/swift/blob/master/docs/SIL.rst#checked-conversions

However, unconditional_checked_cast_value is missed on mayTrap case in current implementation so this commit added it to cover all-case.

This missing case has a risk to remove instruction which should be marked as side-effect, on like Dead Code Elimination, so should be fixed

@freddi-kit freddi-kit changed the title [sil-opt] Fix covering all-case of trapping instruction of mayTrap in sil-opt [sil-opt] Fix covering all-case of trapping instruction of SILInstruction::mayTrap Sep 8, 2020
@theblixguy theblixguy requested a review from eeckstein September 9, 2020 19:15
@freddi-kit
Copy link
Contributor Author

freddi-kit commented Sep 10, 2020

If the current one is correct, I think it would be better to add some comments of it to source code, what do you think?

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.

Can you add a test case in https://github.com/apple/swift/blob/master/test/SILOptimizer/side-effect.sil
As an example, see the test function "sil @checkedcast".

Otherwise LGTM!

@freddi-kit
Copy link
Contributor Author

Oh, sorry for not adding test, let me add it! 👍

@freddi-kit
Copy link
Contributor Author

freddi-kit commented Sep 10, 2020

@eeckstein

I added test of unconditional_checked_cast_value with missing unconditional_checked_cast_addr at 2676839.

If no unconditional_checked_cast_value case in mayTrap, test result is <func=r,param0=>. But now it will be <func=r,param0=;trap> to show it as trap. Please check it.

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.

LGTM, thanks!

@freddi-kit
Copy link
Contributor Author

freddi-kit commented Sep 11, 2020

Thank you for reviewing!

@freddi-kit
Copy link
Contributor Author

Should I run test?

@theblixguy
Copy link
Collaborator

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@theblixguy
Copy link
Collaborator

@swift-ci please test macOS

@theblixguy
Copy link
Collaborator

@swift-ci please test Windows

@theblixguy
Copy link
Collaborator

@swift-ci please test macOS

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2676839

@theblixguy
Copy link
Collaborator

macOS failure should be fixed once swiftlang/swift-package-manager#2924 is merged.

@xedin
Copy link
Contributor

xedin commented Sep 13, 2020

@swift-ci please test macOS platform

@xedin xedin merged commit c56ae1e into swiftlang:master Sep 13, 2020
@freddi-kit freddi-kit deleted the fix/may-trap-condition branch September 13, 2020 05:37
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.

5 participants