Skip to content

Commit 9a0d00f

Browse files
authored
Merge pull request #58735 from eeckstein/fix-sil-serialization-5.7
[5.7] SIL: fix serialization of the `unchecked_ref_cast` instruction
2 parents 502ee1d + 61ea4f1 commit 9a0d00f

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,6 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
13451345
ONEOPERAND_ONETYPE_INST(RefTo##Name) \
13461346
ONEOPERAND_ONETYPE_INST(Name##ToRef)
13471347
#include "swift/AST/ReferenceStorage.def"
1348-
ONEOPERAND_ONETYPE_INST(UncheckedRefCast)
13491348
ONEOPERAND_ONETYPE_INST(UncheckedAddrCast)
13501349
ONEOPERAND_ONETYPE_INST(UncheckedTrivialBitCast)
13511350
ONEOPERAND_ONETYPE_INST(UncheckedBitwiseCast)
@@ -2669,6 +2668,17 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
26692668
failureBB);
26702669
break;
26712670
}
2671+
case SILInstructionKind::UncheckedRefCastInst: {
2672+
assert(RecordKind == SIL_ONE_TYPE_ONE_OPERAND &&
2673+
"Layout should be OneTypeOneOperand.");
2674+
auto *urc = Builder.createUncheckedRefCast(Loc,
2675+
getLocalValue(ValID, getSILType(MF->getType(TyID2),
2676+
(SILValueCategory)TyCategory2, Fn)),
2677+
getSILType(MF->getType(TyID), (SILValueCategory)TyCategory, Fn));
2678+
urc->setForwardingOwnershipKind(decodeValueOwnership(Attr));
2679+
ResultInst = urc;
2680+
break;
2681+
}
26722682
case SILInstructionKind::UncheckedRefCastAddrInst: {
26732683
CanType sourceType = MF->getType(ListOfValues[0])->getCanonicalType();
26742684
// ignore attr.

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 687; // RefAdHocRequirementFunction info in SILFunctionLayout
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 690; // cast ownership serialization
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///

lib/Serialization/SILFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ namespace sil_block {
331331
using SILOneTypeOneOperandLayout = BCRecordLayout<
332332
SIL_ONE_TYPE_ONE_OPERAND,
333333
SILInstOpCodeField,
334-
BCFixed<1>, // Optional attribute
334+
BCFixed<2>, // Optional attribute
335335
TypeIDField,
336336
SILTypeCategoryField,
337337
TypeIDField,

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,8 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
17521752
if (SI.getKind() == SILInstructionKind::ConvertFunctionInst) {
17531753
if (cast<ConvertFunctionInst>(SI).withoutActuallyEscaping())
17541754
attrs |= 0x01;
1755+
} else if (auto *refCast = dyn_cast<UncheckedRefCastInst>(&SI)) {
1756+
attrs = encodeValueOwnership(refCast->getOwnershipKind());
17551757
}
17561758
writeConversionLikeInstruction(cast<SingleValueInstruction>(&SI), attrs);
17571759
break;

test/Serialization/ossa_sil.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -emit-module -module-name ossa -o %t/ossa.swiftmodule %s
3+
// RUN: %target-sil-opt %t/ossa.swiftmodule | %FileCheck %s
4+
5+
sil_stage canonical
6+
7+
import Builtin
8+
import Swift
9+
import SwiftShims
10+
11+
class X {}
12+
13+
// CHECK-LABEL: sil [serialized] [canonical] [ossa] @test_unchecked_ref_cast
14+
sil [serialized] [ossa] @test_unchecked_ref_cast : $@convention(thin) (@guaranteed AnyObject) -> @owned X {
15+
bb0(%0 : @guaranteed $AnyObject):
16+
// CHECK: %1 = unchecked_ref_cast %0 : $AnyObject to $X, forwarding: @unowned
17+
%1 = unchecked_ref_cast %0 : $AnyObject to $X, forwarding: @unowned
18+
%2 = copy_value %1 : $X
19+
return %2 : $X
20+
}
21+

0 commit comments

Comments
 (0)