Skip to content

LoadableByAddress: Fix broken assert #27587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,20 @@ static void convertBBArgType(SILBuilder &argBuilder, SILType newSILType,
}
}

static bool containsFunctionType(CanType ty) {
if (auto tuple = dyn_cast<TupleType>(ty)) {
for (auto elt : tuple.getElementTypes()) {
if (containsFunctionType(elt))
return true;
}
return false;
}
if (auto optionalType = ty.getOptionalObjectType()) {
return containsFunctionType(optionalType);
}
return isa<SILFunctionType>(ty);
}

void LoadableStorageAllocation::convertApplyResults() {
for (auto &BB : *pass.F) {
for (auto &II : BB) {
Expand All @@ -1450,16 +1464,7 @@ void LoadableStorageAllocation::convertApplyResults() {
auto numFuncTy = llvm::count_if(origSILFunctionType->getResults(),
[](const SILResultInfo &origResult) {
auto resultStorageTy = origResult.getSILStorageType();
// Check if it is a function type
if (resultStorageTy.is<SILFunctionType>()) {
return true;
}
// Check if it is an optional function type
auto optionalType = resultStorageTy.getOptionalObjectType();
if (optionalType && optionalType.is<SILFunctionType>()) {
return true;
}
return false;
return containsFunctionType(resultStorageTy.getASTType());
});
assert(numFuncTy != 0 &&
"Expected a SILFunctionType inside the result Type");
Expand Down
8 changes: 8 additions & 0 deletions test/IRGen/big_types_corner_cases.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,11 @@ public extension sr8076_QueryHandler {
return try body(query)
}
}

public func foo() -> Optional<(a: Int?, b: Bool, c: (Int?)->BigStruct?)> {
return nil
}

public func dontAssert() {
let _ = foo()
}