Skip to content

[IRGenDebugInfo] Look through pointer casts #66409

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

Closed

Conversation

felipepiovezan
Copy link
Contributor

This PR contains two commits, both fixing the same issue in different parts of the code base: we fail to look through pointer casts when making codegen decisions. These were exposed by the opaque pointer work, since in this mode most pointer casts are gone.

We decide whether or not to generate shadow copies based on whether an
instruction is an Alloca or not. We should ignore all pointer casts when doing
so, otherwise we may artificially reach the conclusion that the instruction does
not represent an alloca.

Furthermore, once we reach the alloca, we should also check if it is a static
alloca: in that case, no shadow copy is needed.

It may look like this change is not tested, but it is. We were forgetting to do
two things (strip ptr casts + static alloca check). Fixing only one of those
would introduce test failures. Fixing both maintain the existing test behavior.
When deciding whether to generate dbg.declare or dbg.values, we check whether
the variable "storage" is an alloca or not. But this fails to account for no-op
pointer casts.

Some of the tests I updated were expecting really weird behavior. For example,
debug_info_expression was generating an alloca + dbg declare, followed by a
debug value for the same variable.
@felipepiovezan
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Nice!

aschwaighofer added a commit to aschwaighofer/swift that referenced this pull request Jun 14, 2023
Based on swiftlang#66409

With the observation that the pre-opaque world was using bitcast as an
indication that the storage type and the type of the variable were
different. We can recover this information from the storage type of the
alloca and the storage type of the type info.
aschwaighofer added a commit to aschwaighofer/swift that referenced this pull request Jun 14, 2023
Based on swiftlang#66409

With the observation that the pre-opaque world was using bitcast as an
indication that the storage type and the type of the variable were
different. We can recover this information from the storage type of the
alloca and the storage type of the type info.
@felipepiovezan
Copy link
Contributor Author

@aschwaighofer merged a variant of this: #66077

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.

2 participants