Skip to content

Commit 11c8da8

Browse files
committed
SimplifyCFG: add an additional safety check before we try to convert parameters of ABI compatible functions.
This check should not trigger, at least with the current definition of what a convert_function may do. But still it's a good idea to make the check to be on the safe side.
1 parent 4a7a496 commit 11c8da8

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,18 +1891,32 @@ bool SimplifyCFG::simplifyTryApplyBlock(TryApplyInst *TAI) {
18911891
TAI->getModule().getSwiftModule(), TAI->getSubstitutions());
18921892
}
18931893

1894+
auto OrigParamTypes = OrigFnTy->getParameterSILTypes();
1895+
auto TargetParamTypes = TargetFnTy->getParameterSILTypes();
1896+
unsigned numArgs = TAI->getNumArguments();
1897+
1898+
// First check if it is possible to convert all arguments.
1899+
// Currently we believe that castValueToABICompatibleType can handle all
1900+
// cases, so this check should never fail. We just do it to be absolutely
1901+
// sure that we don't crash.
1902+
for (unsigned i = 0; i < numArgs; ++i) {
1903+
if (!canCastValueToABICompatibleType(TAI->getModule(),
1904+
OrigParamTypes[i],
1905+
TargetParamTypes[i])) {
1906+
return false;
1907+
}
1908+
}
1909+
18941910
SmallVector<SILValue, 8> Args;
1895-
for (int i = 0, e = TAI->getNumArguments(); i < e; ++i) {
1911+
for (unsigned i = 0; i < numArgs; ++i) {
18961912
auto Arg = TAI->getArgument(i);
18971913
// Cast argument if required.
18981914
Arg = castValueToABICompatibleType(&Builder, TAI->getLoc(), Arg,
1899-
OrigFnTy->getParameterSILTypes()[i],
1900-
TargetFnTy->getParameterSILTypes()[i]).
1901-
getValue();
1915+
OrigParamTypes[i],
1916+
TargetParamTypes[i]).getValue();
19021917
Args.push_back(Arg);
19031918
}
19041919

1905-
19061920
assert (CalleeFnTy->getParameters().size() == Args.size() &&
19071921
"The number of arguments should match");
19081922

0 commit comments

Comments
 (0)