Skip to content

Commit 683c02c

Browse files
authored
Merge pull request #78728 from augusto2112/fix-resilience-lldb
Fix miscompilations for debugger because of resilience
2 parents dca3e14 + bceb817 commit 683c02c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IRGen/GenDecl.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -6012,6 +6012,14 @@ bool IRGenModule::hasResilientMetadata(ClassDecl *D,
60126012
return false;
60136013
}
60146014

6015+
// Because the debugger can extend non public types outside of their module,
6016+
// also check that "D" is *not* resilient from the module that contains
6017+
// "asViewedFromRootClass".
6018+
if (Context.LangOpts.DebuggerSupport && asViewedFromRootClass &&
6019+
!D->hasResilientMetadata(asViewedFromRootClass->getModuleContext(),
6020+
expansion))
6021+
return false;
6022+
60156023
return D->hasResilientMetadata(getSwiftModule(), expansion);
60166024
}
60176025

lib/IRGen/IRGenSIL.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -8387,9 +8387,17 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
83878387

83888388
auto methodType = i->getType().castTo<SILFunctionType>();
83898389

8390+
AccessLevel methodAccess = method.getDecl()->getEffectiveAccess();
83908391
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());
83918392
bool shouldUseDispatchThunk = false;
8392-
if (IGM.hasResilientMetadata(classDecl, ResilienceExpansion::Maximal)) {
8393+
// Because typechecking for the debugger has more lax rules, check the access
8394+
// level of the getter to decide whether to use a dispatch thunk for the
8395+
// debugger.
8396+
bool shouldUseDispatchThunkIfInDebugger =
8397+
!classDecl->getASTContext().LangOpts.DebuggerSupport ||
8398+
methodAccess == AccessLevel::Public;
8399+
if (IGM.hasResilientMetadata(classDecl, ResilienceExpansion::Maximal) &&
8400+
shouldUseDispatchThunkIfInDebugger) {
83938401
shouldUseDispatchThunk = true;
83948402
} else if (IGM.getOptions().VirtualFunctionElimination) {
83958403
// For VFE, use a thunk if the target class is in another module. This

0 commit comments

Comments
 (0)