@@ -3073,6 +3073,13 @@ class CFunctionConventions : public CFunctionTypeConventions {
30733073 }
30743074
30753075 ResultConvention getResult (const TypeLowering &tl) const override {
3076+ // C++ constructors return indirectly.
3077+ // TODO: this may be different depending on the ABI, so we may have to
3078+ // check with clang here.
3079+ if (isa<clang::CXXConstructorDecl>(TheDecl)) {
3080+ return ResultConvention::Indirect;
3081+ }
3082+
30763083 if (isCFTypedef (tl, TheDecl->getReturnType ())) {
30773084 // The CF attributes aren't represented in the type, so we need
30783085 // to check them here.
@@ -3177,15 +3184,19 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
31773184 }
31783185
31793186 if (auto method = dyn_cast<clang::CXXMethodDecl>(clangDecl)) {
3180- AbstractionPattern origPattern = AbstractionPattern::getCXXMethod (origType, method,
3181- foreignInfo.self );
3182- bool isMutating =
3183- TC.Context .getClangModuleLoader ()->isCXXMethodMutating (method);
3184- auto conventions = CXXMethodConventions (method, isMutating);
3185- return getSILFunctionType (TC, TypeExpansionContext::minimal (), origPattern,
3186- substInterfaceType, extInfoBuilder, conventions,
3187- foreignInfo, constant, constant, None,
3188- ProtocolConformanceRef ());
3187+ // Static methods and ctors should be lowered like plane functions
3188+ // (case below).
3189+ if (!isa<clang::CXXConstructorDecl>(method) || method->isStatic ()) {
3190+ AbstractionPattern origPattern = AbstractionPattern::getCXXMethod (origType, method,
3191+ foreignInfo.self );
3192+ bool isMutating =
3193+ TC.Context .getClangModuleLoader ()->isCXXMethodMutating (method);
3194+ auto conventions = CXXMethodConventions (method, isMutating);
3195+ return getSILFunctionType (TC, TypeExpansionContext::minimal (), origPattern,
3196+ substInterfaceType, extInfoBuilder, conventions,
3197+ foreignInfo, constant, constant, None,
3198+ ProtocolConformanceRef ());
3199+ }
31893200 }
31903201
31913202 if (auto func = dyn_cast<clang::FunctionDecl>(clangDecl)) {
0 commit comments