Skip to content

Commit d444a75

Browse files
committed
Compute the return type of c++ constructors without calling arrangeCXXStructorDeclaration
1 parent 9ddee0f commit d444a75

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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");

lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3511,7 +3511,10 @@ llvm::Constant *swift::irgen::emitCXXConstructorThunkIfNeeded(
35113511
emitCXXConstructorCall(subIGF, ctor, ctorFnType, ctorAddress, Args);
35123512
if (isa<llvm::InvokeInst>(call))
35133513
IGM.emittedForeignFunctionThunksWithExceptionTraps.insert(thunk);
3514-
subIGF.Builder.CreateRetVoid();
3514+
if (ctorFnType->getReturnType()->isVoidTy())
3515+
subIGF.Builder.CreateRetVoid();
3516+
else
3517+
subIGF.Builder.CreateRet(call);
35153518

35163519
return thunk;
35173520
}

lib/IRGen/GenStruct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ namespace {
620620
auto clangFnAddr =
621621
IGF.IGM.getAddrOfClangGlobalDecl(globalDecl, NotForDefinition);
622622
auto callee = cast<llvm::Function>(clangFnAddr->stripPointerCasts());
623-
Signature signature = IGF.IGM.getSignature(fnType);
623+
Signature signature = IGF.IGM.getSignature(fnType, copyConstructor);
624624
std::string name = "__swift_cxx_copy_ctor" + callee->getName().str();
625625
auto *origClangFnAddr = clangFnAddr;
626626
clangFnAddr = emitCXXConstructorThunkIfNeeded(

0 commit comments

Comments
 (0)