Skip to content

Commit bceb817

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
1 parent c20a5b7 commit bceb817

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
@@ -6010,6 +6010,14 @@ bool IRGenModule::hasResilientMetadata(ClassDecl *D,
60106010
return false;
60116011
}
60126012

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

lib/IRGen/IRGenSIL.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8380,9 +8380,17 @@ void IRGenSILFunction::visitClassMethodInst(swift::ClassMethodInst *i) {
83808380
SILDeclRef method = i->getMember().getOverriddenVTableEntry();
83818381
auto methodType = i->getType().castTo<SILFunctionType>();
83828382

8383+
AccessLevel methodAccess = method.getDecl()->getEffectiveAccess();
83838384
auto *classDecl = cast<ClassDecl>(method.getDecl()->getDeclContext());
83848385
bool shouldUseDispatchThunk = false;
8385-
if (IGM.hasResilientMetadata(classDecl, ResilienceExpansion::Maximal)) {
8386+
// Because typechecking for the debugger has more lax rules, check the access
8387+
// level of the getter to decide whether to use a dispatch thunk for the
8388+
// debugger.
8389+
bool shouldUseDispatchThunkIfInDebugger =
8390+
!classDecl->getASTContext().LangOpts.DebuggerSupport ||
8391+
methodAccess == AccessLevel::Public;
8392+
if (IGM.hasResilientMetadata(classDecl, ResilienceExpansion::Maximal) &&
8393+
shouldUseDispatchThunkIfInDebugger) {
83868394
shouldUseDispatchThunk = true;
83878395
} else if (IGM.getOptions().VirtualFunctionElimination) {
83888396
// For VFE, use a thunk if the target class is in another module. This

0 commit comments

Comments
 (0)