Skip to content

Commit 1dd4a99

Browse files
authored
Merge pull request #82916 from jckarter/preconcurrency-indirect-return-6.2
[6.2] SILGen: Bitcast indirect returns that differ only in concurrency annotations.
2 parents 9f9d265 + 6f4748c commit 1dd4a99

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

include/swift/SIL/SILType.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,13 @@ class SILType {
754754
SILType subst(SILModule &M, SubstitutionMap subs,
755755
TypeExpansionContext context) const;
756756

757+
/// Strip concurrency annotations from the representation type.
758+
SILType stripConcurrency(bool recursive, bool dropGlobalActor) {
759+
auto strippedASTTy = getASTType()->stripConcurrency(recursive, dropGlobalActor);
760+
return SILType::getPrimitiveType(strippedASTTy->getCanonicalType(),
761+
getCategory());
762+
}
763+
757764
/// Return true if this type references a "ref" type that has a single pointer
758765
/// representation. Class existentials do not always qualify.
759766
bool isHeapObjectReferenceType() const;

lib/SILGen/SILGenApply.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,15 +1967,21 @@ static void emitRawApply(SILGenFunction &SGF,
19671967
SmallVector<SILValue, 4> argValues;
19681968

19691969
// Add the buffers for the indirect results if needed.
1970-
#ifndef NDEBUG
1971-
assert(indirectResultAddrs.size() == substFnConv.getNumIndirectSILResults());
19721970
unsigned resultIdx = 0;
1973-
for (auto indResultTy :
1974-
substFnConv.getIndirectSILResultTypes(SGF.getTypeExpansionContext())) {
1975-
assert(indResultTy == indirectResultAddrs[resultIdx++]->getType());
1971+
for (auto indResultTy : substFnConv.getIndirectSILResultTypes(SGF.getTypeExpansionContext())) {
1972+
auto indResultAddr = indirectResultAddrs[resultIdx++];
1973+
1974+
if (indResultAddr->getType() != indResultTy) {
1975+
// Bitcast away differences in Sendable, global actor, etc.
1976+
if (indResultAddr->getType().stripConcurrency(/*recursive*/ true, /*dropGlobalActor*/ true)
1977+
== indResultTy.stripConcurrency(/*recursive*/ true, /*dropGlobalActor*/ true)) {
1978+
indResultAddr = SGF.B.createUncheckedAddrCast(loc, indResultAddr, indResultTy);
1979+
}
1980+
}
1981+
assert(indResultTy == indResultAddr->getType());
1982+
1983+
argValues.push_back(indResultAddr);
19761984
}
1977-
#endif
1978-
argValues.append(indirectResultAddrs.begin(), indirectResultAddrs.end());
19791985

19801986
assert(!!indirectErrorAddr == substFnConv.hasIndirectSILErrorResults());
19811987
if (indirectErrorAddr)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
@preconcurrency
4+
func test() -> (any Sendable)? { nil }
5+
6+
// CHECK-LABEL: sil {{.*}} @$s{{.*}}callWithPreconcurrency
7+
func callWithPreconcurrency() {
8+
// CHECK: unchecked_addr_cast {{.*}} to $*Optional<any Sendable>
9+
let x = test()
10+
}

0 commit comments

Comments
 (0)