@@ -1375,8 +1375,12 @@ void SignatureExpansion::expandExternalSignatureTypes() {
13751375 IGM.getSILModule (), FnType, TypeExpansionContext::minimal ()));
13761376 }();
13771377
1378- // Convert the SIL result type to a Clang type.
1379- auto clangResultTy = IGM.getClangType (SILResultTy);
1378+ // Convert the SIL result type to a Clang type. If this is for a c++
1379+ // constructor, use 'void' as the return type to arrange the function type.
1380+ auto clangResultTy = IGM.getClangType (
1381+ cxxCtorDecl
1382+ ? SILType::getPrimitiveObjectType (IGM.Context .TheEmptyTupleType )
1383+ : SILResultTy);
13801384
13811385 // Now convert the parameters to Clang types.
13821386 auto params = FnType->getParameters ();
@@ -1445,14 +1449,10 @@ void SignatureExpansion::expandExternalSignatureTypes() {
14451449 // Generate function info for this signature.
14461450 auto extInfo = clang::FunctionType::ExtInfo ();
14471451
1448- if (cxxCtorDecl)
1449- ForeignInfo.ClangInfo = &clang::CodeGen::arrangeCXXStructorDeclaration (
1450- IGM.ClangCodeGen ->CGM (), {cxxCtorDecl, clang::Ctor_Complete});
1451- else
1452- ForeignInfo.ClangInfo = &clang::CodeGen::arrangeFreeFunctionCall (
1453- IGM.ClangCodeGen ->CGM (), clangResultTy, paramTys, extInfo,
1454- clang::CodeGen::RequiredArgs::All);
1455- auto &FI = *ForeignInfo.ClangInfo ;
1452+ auto &FI = clang::CodeGen::arrangeFreeFunctionCall (IGM.ClangCodeGen ->CGM (),
1453+ clangResultTy, paramTys, extInfo,
1454+ clang::CodeGen::RequiredArgs::All);
1455+ ForeignInfo.ClangInfo = &FI;
14561456
14571457 assert (FI.arg_size () == paramTys.size () &&
14581458 " Expected one ArgInfo for each parameter type!" );
@@ -1596,7 +1596,12 @@ void SignatureExpansion::expandExternalSignatureTypes() {
15961596 for (auto i : indices (paramTys).slice (firstParamToLowerNormally))
15971597 emitArg (i);
15981598
1599- if (returnInfo.isIndirect () || returnInfo.isIgnore ()) {
1599+ if (cxxCtorDecl) {
1600+ ResultIRType = cast<llvm::Function>(IGM.getAddrOfClangGlobalDecl (
1601+ {cxxCtorDecl, clang::Ctor_Complete},
1602+ (ForDefinition_t) false ))
1603+ ->getReturnType ();
1604+ } else if (returnInfo.isIndirect () || returnInfo.isIgnore ()) {
16001605 ResultIRType = IGM.VoidTy ;
16011606 } else {
16021607 ResultIRType = returnInfo.getCoerceToType ();
@@ -3996,12 +4001,6 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
39964001 // swiftcall function pointers through SIL as C functions anyway.
39974002 assert (FI.getExtParameterInfo (i).getABI () == clang::ParameterABI::Ordinary);
39984003
3999- assert ((!silConv.isSILIndirect (params[i - firstParam]) ||
4000- AI.getKind () == clang::CodeGen::ABIArgInfo::Direct ||
4001- AI.getKind () == clang::CodeGen::ABIArgInfo::Indirect) &&
4002- " indirect SIL types passed indirectly should be classified as "
4003- " either Direct or Indirect" );
4004-
40054004 // Add a padding argument if required.
40064005 if (auto *padType = AI.getPaddingType ())
40074006 out.add (llvm::UndefValue::get (padType));
@@ -4053,15 +4052,6 @@ static void externalizeArguments(IRGenFunction &IGF, const Callee &callee,
40534052 case clang::CodeGen::ABIArgInfo::IndirectAliased:
40544053 llvm_unreachable (" not implemented" );
40554054 case clang::CodeGen::ABIArgInfo::Indirect: {
4056- // If this is a SIL type passed indirectly, avoid emitting a redundant
4057- // initializing copy.
4058- if (silConv.isSILIndirect (params[i - firstParam])) {
4059- assert (paramType.isAddress () && " SIL type is not an address?" );
4060- auto addr = in.claimNext ();
4061- out.add (addr);
4062- break ;
4063- }
4064-
40654055 auto &ti = cast<LoadableTypeInfo>(IGF.getTypeInfo (paramType));
40664056
40674057 auto temp = ti.allocateStack (IGF, paramType, " indirect-temporary" );
0 commit comments