Skip to content

Commit b6dedb7

Browse files
authored
Merge pull request #25999 from slavapestov/sil-verifier-super-vtable
SIL: Fix SIL verifier's VerifyClassMethodVisitor
2 parents 9bd600e + d38a2ea commit b6dedb7

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,47 +2868,25 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
28682868
: public SILVTableVisitor<VerifyClassMethodVisitor>
28692869
{
28702870
public:
2871-
SILDeclRef MethodToSee;
2871+
SILDeclRef Method;
28722872
bool Seen = false;
2873-
2874-
VerifyClassMethodVisitor(ClassDecl *theClass,
2875-
SILDeclRef method)
2876-
: MethodToSee(method)
2877-
{
2873+
2874+
VerifyClassMethodVisitor(SILDeclRef method)
2875+
: Method(method.getOverriddenVTableEntry()) {
2876+
auto *theClass = cast<ClassDecl>(Method.getDecl()->getDeclContext());
28782877
addVTableEntries(theClass);
28792878
}
2880-
2881-
bool methodMatches(SILDeclRef method) {
2882-
auto methodToCheck = MethodToSee;
2883-
do {
2884-
if (method == methodToCheck) {
2885-
return true;
2886-
}
2887-
} while ((methodToCheck = methodToCheck.getNextOverriddenVTableEntry()));
28882879

2889-
return false;
2890-
}
2891-
28922880
void addMethod(SILDeclRef method) {
28932881
if (Seen)
28942882
return;
2895-
if (methodMatches(method))
2896-
Seen = true;
2897-
}
2898-
2899-
void addMethodOverride(SILDeclRef base, SILDeclRef derived) {
2900-
if (Seen)
2901-
return;
2902-
// The derived method should already have been checked.
2903-
// Test against the overridden base.
2904-
if (methodMatches(base))
2883+
if (method == Method)
29052884
Seen = true;
29062885
}
29072886

2908-
2909-
void addPlaceholder(MissingMemberDecl *) {
2910-
/* no-op */
2911-
}
2887+
void addMethodOverride(SILDeclRef base, SILDeclRef derived) {}
2888+
2889+
void addPlaceholder(MissingMemberDecl *) {}
29122890
};
29132891

29142892
void checkClassMethodInst(ClassMethodInst *CMI) {
@@ -2935,10 +2913,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
29352913
"extension method cannot be dispatched natively");
29362914

29372915
// The method ought to appear in the class vtable.
2938-
require(VerifyClassMethodVisitor(
2939-
operandType.getASTType()->getMetatypeInstanceType()
2940-
->getClassOrBoundGenericClass(),
2941-
member).Seen,
2916+
require(VerifyClassMethodVisitor(member).Seen,
29422917
"method does not appear in the class's vtable");
29432918
}
29442919

@@ -2972,10 +2947,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
29722947
"super_method must look up a class method");
29732948

29742949
// The method ought to appear in the class vtable.
2975-
require(VerifyClassMethodVisitor(
2976-
operandType.getASTType()->getMetatypeInstanceType()
2977-
->getClassOrBoundGenericClass(),
2978-
member).Seen,
2950+
require(VerifyClassMethodVisitor(member).Seen,
29792951
"method does not appear in the class's vtable");
29802952
}
29812953

test/SILGen/super.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ public class ChildToFixedParent : OutsideParent {
171171
// CHECK: } // end sil function '$s5super18ChildToFixedParentC11returnsSelfACXDyFZ'
172172
}
173173

174+
// https://bugs.swift.org/browse/SR-10260 - super.foo() call across a module
175+
// boundary from a subclass that does not override foo().
176+
public class SuperCallToNonOverriddenMethod : OutsideParent {
177+
public func newMethod() {
178+
super.method()
179+
}
180+
}
181+
174182
public extension ResilientOutsideChild {
175183
public func callSuperMethod() {
176184
super.method()

0 commit comments

Comments
 (0)