@@ -1260,6 +1260,26 @@ void SwiftMergeFunctions::writeThunk(Function *ToFunc, Function *Thunk,
1260
1260
++NumSwiftThunksWritten;
1261
1261
}
1262
1262
1263
+ static llvm::AttributeList
1264
+ fixUpTypesInByValAndStructRetAttributes (llvm::FunctionType *fnType,
1265
+ llvm::AttributeList attrList) {
1266
+ auto &context = fnType->getContext ();
1267
+ for (unsigned i = 0 ; i < fnType->getNumParams (); ++i) {
1268
+ auto paramTy = fnType->getParamType (i);
1269
+ auto attrListIndex = llvm::AttributeList::FirstArgIndex + i;
1270
+ if (attrList.hasParamAttr (i, llvm::Attribute::StructRet) &&
1271
+ paramTy->getPointerElementType () != attrList.getParamStructRetType (i))
1272
+ attrList = attrList.replaceAttributeTypeAtIndex (
1273
+ context, attrListIndex, llvm::Attribute::StructRet,
1274
+ paramTy->getPointerElementType ());
1275
+ if (attrList.hasParamAttr (i, llvm::Attribute::ByVal) &&
1276
+ paramTy->getPointerElementType () != attrList.getParamByValType (i))
1277
+ attrList = attrList.replaceAttributeTypeAtIndex (
1278
+ context, attrListIndex, llvm::Attribute::ByVal,
1279
+ paramTy->getPointerElementType ());
1280
+ }
1281
+ return attrList;
1282
+ }
1263
1283
// / Replace direct callers of Old with New. Also add parameters to the call to
1264
1284
// / \p New, which are defined by the FuncIdx's value in \p Params.
1265
1285
bool SwiftMergeFunctions::replaceDirectCallers (Function *Old, Function *New,
@@ -1329,9 +1349,11 @@ bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New,
1329
1349
NewCI->setCallingConv (CI->getCallingConv ());
1330
1350
// Don't transfer attributes from the function to the callee. Function
1331
1351
// attributes typically aren't relevant to the calling convention or ABI.
1332
- NewCI-> setAttributes ( AttributeList::get (Context, /* FnAttrs=*/ AttributeSet (),
1352
+ auto newAttrList = AttributeList::get (Context, /* FnAttrs=*/ AttributeSet (),
1333
1353
NewPAL.getRetAttrs (),
1334
- NewArgAttrs));
1354
+ NewArgAttrs);
1355
+ newAttrList = fixUpTypesInByValAndStructRetAttributes (FType, newAttrList);
1356
+ NewCI->setAttributes (newAttrList);
1335
1357
CI->replaceAllUsesWith (NewCI);
1336
1358
CI->eraseFromParent ();
1337
1359
}
0 commit comments