Skip to content

Commit 0822ce5

Browse files
Merge pull request #27587 from aschwaighofer/loadable_by_address_fix_assert
LoadableByAddress: Fix broken assert
2 parents ce7aa3c + e8492e9 commit 0822ce5

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,20 @@ static void convertBBArgType(SILBuilder &argBuilder, SILType newSILType,
14261426
}
14271427
}
14281428

1429+
static bool containsFunctionType(CanType ty) {
1430+
if (auto tuple = dyn_cast<TupleType>(ty)) {
1431+
for (auto elt : tuple.getElementTypes()) {
1432+
if (containsFunctionType(elt))
1433+
return true;
1434+
}
1435+
return false;
1436+
}
1437+
if (auto optionalType = ty.getOptionalObjectType()) {
1438+
return containsFunctionType(optionalType);
1439+
}
1440+
return isa<SILFunctionType>(ty);
1441+
}
1442+
14291443
void LoadableStorageAllocation::convertApplyResults() {
14301444
for (auto &BB : *pass.F) {
14311445
for (auto &II : BB) {
@@ -1450,16 +1464,7 @@ void LoadableStorageAllocation::convertApplyResults() {
14501464
auto numFuncTy = llvm::count_if(origSILFunctionType->getResults(),
14511465
[](const SILResultInfo &origResult) {
14521466
auto resultStorageTy = origResult.getSILStorageType();
1453-
// Check if it is a function type
1454-
if (resultStorageTy.is<SILFunctionType>()) {
1455-
return true;
1456-
}
1457-
// Check if it is an optional function type
1458-
auto optionalType = resultStorageTy.getOptionalObjectType();
1459-
if (optionalType && optionalType.is<SILFunctionType>()) {
1460-
return true;
1461-
}
1462-
return false;
1467+
return containsFunctionType(resultStorageTy.getASTType());
14631468
});
14641469
assert(numFuncTy != 0 &&
14651470
"Expected a SILFunctionType inside the result Type");

test/IRGen/big_types_corner_cases.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,11 @@ public extension sr8076_QueryHandler {
346346
return try body(query)
347347
}
348348
}
349+
350+
public func foo() -> Optional<(a: Int?, b: Bool, c: (Int?)->BigStruct?)> {
351+
return nil
352+
}
353+
354+
public func dontAssert() {
355+
let _ = foo()
356+
}

0 commit comments

Comments
 (0)