@@ -1315,6 +1315,17 @@ void SignatureExpansion::expandExternalSignatureTypes() {
1315
1315
// Swift parameters list?
1316
1316
size_t clangToSwiftParamOffset = paramTys.size ();
1317
1317
1318
+ // This is exactly the same as "params" but without thin metatypes. This must
1319
+ // exist so that when the path for "Indirect" arguments looks for the
1320
+ // SILParameterInfo for a given index, we get the parameter info for the
1321
+ // coorisponding clang type's index and not a "random" parameter's info.
1322
+ //
1323
+ // This is only an issue in very rare cases when we have a constructor that
1324
+ // looks like this: (T, @thin U.Type) -> @out U. In this case "params" will
1325
+ // contain two elements and "paramTys" will contain two elements so the
1326
+ // "Indirect" argument path gets confused and selects the second parameter
1327
+ // (the thin metatype) instead of the first one.
1328
+ SmallVector<SILParameterInfo, 4 > adjustedSILParams;
1318
1329
// Convert each parameter to a Clang type.
1319
1330
for (auto param : params) {
1320
1331
auto clangTy = IGM.getClangType (param, FnType);
@@ -1324,6 +1335,7 @@ void SignatureExpansion::expandExternalSignatureTypes() {
1324
1335
continue ;
1325
1336
}
1326
1337
paramTys.push_back (clangTy);
1338
+ adjustedSILParams.push_back (param);
1327
1339
}
1328
1340
1329
1341
// Generate function info for this signature.
@@ -1413,7 +1425,7 @@ void SignatureExpansion::expandExternalSignatureTypes() {
1413
1425
case clang::CodeGen::ABIArgInfo::Indirect: {
1414
1426
assert (i >= clangToSwiftParamOffset &&
1415
1427
" Unexpected index for indirect byval argument" );
1416
- auto ¶m = params [i - clangToSwiftParamOffset];
1428
+ auto ¶m = adjustedSILParams [i - clangToSwiftParamOffset];
1417
1429
auto paramTy = getSILFuncConventions ().getSILType (
1418
1430
param, IGM.getMaximalTypeExpansionContext ());
1419
1431
auto ¶mTI = cast<FixedTypeInfo>(IGM.getTypeInfo (paramTy));
0 commit comments