Skip to content

Disable SROA debug info for variables with expressions #61168

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
Sep 21, 2022

Conversation

adrian-prantl
Copy link
Contributor

Currently the SROA just overwrites already-existing expressions on variables. When SROA is recursively run on a data structure this leads to nonsensical expressions such as

type $*Outer, expr op_fragment:#Inner.x

instead of

type $*Outer, expr op_fragment:#Outer.inner op_fragment:#Inner.x

The (nonsensical) LLVM IR generated from this violates some assumptions in LLVM for example, if a struct has multiple members of the same type, you can end up with multiple dbg.declare intrinsics claiming to describe the same variable). As a quick fix, this patch detects this situation and drops the debug info. A proper fix shouldn't be too difficult to implement though.

rdar://99874371

@adrian-prantl
Copy link
Contributor Author

@swift-ci test

@adrian-prantl
Copy link
Contributor Author

FYI, this is in response to this build failure: https://ci.swift.org/job/swift-syntax-PR-macOS/609/consoleText

// TODO: Handle DIExpr that is already attached
NewDebugVarInfo->DIExpr = SILDebugInfoExpression::createFragment(VD);

NewDebugVarInfo->DIExpr.append(
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking: what if we don't clear out DIExpr from the existing VarInfo in SILDebugVariable::createFromAllocation so that this line will append fragment of the inner member. But then I realized we can't have more than one fragment inside a single DIExpression, right? If that's the case, then I do think this is the best solution we have now (until we have the infrastructure to merge two fragments inside a DIExpression)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right — just appending the fragments would be the right thing to do, but it's currently not actually supported. I don't think there's much missing from making this work though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! then I think this LGTM.

Currently the SROA just overwrites already-existing expressions on
variables. When SROA is recursively run on a data structure this leads to
nonsensical expressions such as

  type $*Outer, expr op_fragment:#Inner.x

instead of

  type $*Outer, expr op_fragment:#Outer.inner op_fragment:#Inner.x

The (nonsensical) LLVM IR generated from this violates some assumptions in LLVM
for example, if a struct has multiple members of the same type, you can end up
with multiple dbg.declare intrinsics claiming to describe the same variable). As
a quick fix, this patch detects this situation and drops the debug info. A
proper fix shouldn't be too difficult to implement though.

rdar://99874371
@adrian-prantl
Copy link
Contributor Author

@swift-ci test

2 similar comments
@adrian-prantl
Copy link
Contributor Author

@swift-ci test

@adrian-prantl
Copy link
Contributor Author

@swift-ci test

@adrian-prantl
Copy link
Contributor Author

The windows build failure looks unrelated.

@adrian-prantl adrian-prantl merged commit 1f8a5d6 into swiftlang:main Sep 21, 2022
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