Skip to content

Fix an assert in collectUses when handling unknown index offsets. #38757

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
Aug 5, 2021

Conversation

meg-gupta
Copy link
Contributor

Picking up the fix from #38492. Added tests.

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta
Copy link
Contributor Author

Also need a follow up fix to recognize the offset accurately when there is a builtin "truncOrBitCast_Int64_Word" with a literal.

AccessPathDefUseTraversal accumulates the offsets that it has seen on
the def-use walk while visiting index_addr and casts.

This is quite tricky because either the AccessPath being matched or
the def-use chain could contain unknown offsets. We need to correctly
classify all cases as either an exact, inner, or overlapping match.

For SIL like this

 %91 = integer_literal $Builtin.Int64, 0
 %113 = builtin "truncOrBitCast_Int64_Word"(%91 : $Builtin.Int64) : $Builtin.Word
 %115 = index_addr %114 : $*MyStruct, %113 : $Builtin.Word
 %119 = struct_element_addr %115 : $*MyStruct, #MyStruct.klass

We have Path: (@unknown,#0)

There are two issues

(1) When AccessPathDefUseTraversal::checkAndUpdateOffset visits the
struct_element_addr, it fails to pop the unknown offset from the
expected path but continues trying to handle the struct_element_addr
and hits an assert. This PR fixes this.

(2) If the builtin "truncOrBitCast_Int64_Word" comes from a literal,
we should not treat it as an unknown offset (given that the literal is
within the size of a word). Added a test for this case, we should be able
to identify the access path accurately in this.
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Aug 5, 2021

Build failed
Swift Test Linux Platform
Git Sha - 2c7bc8a2b03f88cc63ccfeb374748bb0d0e1763e

@swift-ci
Copy link
Contributor

swift-ci commented Aug 5, 2021

Build failed
Swift Test OS X Platform
Git Sha - 2c7bc8a2b03f88cc63ccfeb374748bb0d0e1763e

@meg-gupta
Copy link
Contributor Author

@swift-ci test OSX platform

@meg-gupta
Copy link
Contributor Author

@swift-ci test Linux platform

@meg-gupta
Copy link
Contributor Author

@swift-ci test macOS platform

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