Skip to content

Fix miscompilations for debugger because of resilience #78728

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
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6010,6 +6010,14 @@ bool IRGenModule::hasResilientMetadata(ClassDecl *D,
return false;
}

// Because the debugger can extend non public types outside of their module,
// also check that "D" is *not* resilient from the module that contains
// "asViewedFromRootClass".
if (Context.LangOpts.DebuggerSupport && asViewedFromRootClass &&
!D->hasResilientMetadata(asViewedFromRootClass->getModuleContext(),
expansion))
return false;

return D->hasResilientMetadata(getSwiftModule(), expansion);
}

Expand Down
10 changes: 9 additions & 1 deletion lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8380,9 +8380,17 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
SILDeclRef method = i->getMember().getOverriddenVTableEntry();
auto methodType = i->getType().castTo<SILFunctionType>();

AccessLevel methodAccess = method.getDecl()->getEffectiveAccess();
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());
bool shouldUseDispatchThunk = false;
if (IGM.hasResilientMetadata(classDecl, ResilienceExpansion::Maximal)) {
// Because typechecking for the debugger has more lax rules, check the access
// level of the getter to decide whether to use a dispatch thunk for the
// debugger.
bool shouldUseDispatchThunkIfInDebugger =
!classDecl->getASTContext().LangOpts.DebuggerSupport ||
Copy link
Contributor

Choose a reason for hiding this comment

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

IGM.Context

methodAccess == AccessLevel::Public;
if (IGM.hasResilientMetadata(classDecl, ResilienceExpansion::Maximal) &&
shouldUseDispatchThunkIfInDebugger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be tested by compiling Swift code to IR and passing -debugger-support?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that but it's not enough. To look up private classes LLDB implements the DebuggerClient interface, without that we can't write a test that can extend a non-public type in a different module, to emulate LLDB's behavior.

shouldUseDispatchThunk = true;
} else if (IGM.getOptions().VirtualFunctionElimination) {
// For VFE, use a thunk if the target class is in another module. This
Expand Down