Skip to content

Commit b4966a4

Browse files
committed
SIL: Don't serialize SILFunction declarations in witness tables if they don't have a valid linkage for "fragile ref".
E.g. a serialized witness table must not reference a private function. Just like a serialized function must not reference a private function.
1 parent 47d02d2 commit b4966a4

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

include/swift/SIL/SILWitnessTable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class SILWitnessTable : public llvm::ilist_node<SILWitnessTable>,
4848
/// The method required.
4949
SILDeclRef Requirement;
5050
/// The witness for the method.
51-
/// This can be null in case dead function elimination has removed the method.
51+
/// This can be null in case dead function elimination has removed the method
52+
/// or if the method was not serialized (for de-serialized witness tables).
5253
SILFunction *Witness;
5354
};
5455

lib/SIL/IR/SILDefaultWitnessTable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ convertToDefinition(ArrayRef<Entry> entries) {
9090
// Bump the reference count of witness functions referenced by this table.
9191
for (auto entry : getEntries()) {
9292
if (entry.isValid() && entry.getKind() == SILWitnessTable::Method) {
93-
entry.getMethodWitness().Witness->incrementRefCount();
93+
if (SILFunction *f = entry.getMethodWitness().Witness)
94+
f->incrementRefCount();
9495
}
9596
}
9697
}
@@ -105,7 +106,8 @@ SILDefaultWitnessTable::~SILDefaultWitnessTable() {
105106
// Drop the reference count of witness functions referenced by this table.
106107
for (auto entry : getEntries()) {
107108
if (entry.isValid() && entry.getKind() == SILWitnessTable::Method) {
108-
entry.getMethodWitness().Witness->decrementRefCount();
109+
if (SILFunction *f = entry.getMethodWitness().Witness)
110+
f->decrementRefCount();
109111
}
110112
}
111113
}

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5958,6 +5958,8 @@ void SILDefaultWitnessTable::verify(const SILModule &M) const {
59585958
continue;
59595959

59605960
SILFunction *F = E.getMethodWitness().Witness;
5961+
if (!F)
5962+
continue;
59615963

59625964
#if 0
59635965
// FIXME: For now, all default witnesses are private.

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,8 @@ void SILSerializer::writeSILWitnessTableEntry(
26662666
SmallVector<ValueID, 4> ListOfValues;
26672667
handleSILDeclRef(S, methodWitness.Requirement, ListOfValues);
26682668
IdentifierID witnessID = 0;
2669-
if (SILFunction *witness = methodWitness.Witness) {
2669+
SILFunction *witness = methodWitness.Witness;
2670+
if (witness && witness->hasValidLinkageForFragileRef()) {
26702671
addReferencedSILFunction(witness, true);
26712672
witnessID = S.addUniquedStringRef(witness->getName());
26722673
}

0 commit comments

Comments
 (0)