Skip to content

Commit 2debac5

Browse files
authored
Merge pull request swiftlang#74984 from eeckstein/fix-vtable-specializer-6.0
[6.0] Fix a SourceKitCrash in the VTableSpecializer pass
2 parents 6b612c8 + 04e1580 commit 2debac5

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ ERROR(global_must_be_compile_time_const,none,
374374
"global variable must be a compile-time constant", ())
375375
ERROR(non_final_generic_class_function,none,
376376
"classes cannot have non-final generic fuctions in embedded Swift", ())
377+
ERROR(cannot_specialize_class,none,
378+
"cannot specialize %0 because class definition is not available (make sure to build with -wmo)", (Type))
377379
ERROR(embedded_swift_existential_type,none,
378380
"cannot use a value of protocol type %0 in embedded Swift", (Type))
379381
ERROR(embedded_swift_existential,none,

lib/SILOptimizer/Transforms/VTableSpecializer.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ SILVTable *swift::specializeVTableForType(SILType classTy, SILModule &module,
165165
ClassDecl *classDecl = genClassTy->getDecl();
166166
SILVTable *origVtable = module.lookUpVTable(classDecl);
167167
if (!origVtable) {
168-
llvm::errs() << "No vtable available for "
169-
<< genClassTy->getDecl()->getName() << '\n';
170-
llvm::report_fatal_error("no vtable");
168+
// This cannot occur in regular builds - only if built without wmo, which
169+
// can only happen in SourceKit.
170+
// Not ideal, but better than a SourceKit crash.
171+
module.getASTContext().Diags.diagnose(
172+
SourceLoc(), diag::cannot_specialize_class, classTy.getASTType());
173+
return nullptr;
171174
}
172175

173176
SubstitutionMap subs = astType->getContextSubstitutionMap(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// TODO: This test passes locally on my machine, but fails for an unknown reason in CI
5+
// REQUIRES: rdar130167087
6+
7+
//--- secondary.swift
8+
9+
final public class X<T> {
10+
var x: T
11+
12+
init(_ t: T) { x = t}
13+
14+
public func foo() -> T { x }
15+
}
16+
17+
//--- primary.swift
18+
19+
// RUN: %sourcekitd-test -req=diags %t/primary.swift -- %t/primary.swift %t/secondary.swift -enable-experimental-feature Embedded
20+
21+
// check that SourceKit does not crash on this
22+
23+
public func testit() -> X<Int> {
24+
return X(27)
25+
}
26+

0 commit comments

Comments
 (0)