Skip to content

Commit 6d680aa

Browse files
committed
Fix miscompilations for debugger because of resilience
This patch fixes two instances of the compiler embedded in LLDB miscompiling code for expression evaluation, because of a combination of the debugger's access to private types and resilience, which would cause the generated code to access fields indirectly through resilience functions that were never emitted. rdar://137876089 (cherry picked from commit bceb817)
1 parent 447e13b commit 6d680aa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6009,6 +6009,14 @@ bool IRGenModule::hasResilientMetadata(ClassDecl *D,
60096009
return false;
60106010
}
60116011

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

lib/IRGen/IRGenSIL.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8390,9 +8390,17 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
83908390

83918391
auto methodType = i->getType().castTo<SILFunctionType>();
83928392

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

0 commit comments

Comments
 (0)