@@ -3005,6 +3005,13 @@ class CFunctionConventions : public CFunctionTypeConventions {
30053005 }
30063006
30073007 ResultConvention getResult (const TypeLowering &tl) const override {
3008+ // C++ constructors return indirectly.
3009+ // TODO: this may be different depending on the ABI, so we may have to
3010+ // check with clang here.
3011+ if (isa<clang::CXXConstructorDecl>(TheDecl)) {
3012+ return ResultConvention::Indirect;
3013+ }
3014+
30083015 if (isCFTypedef (tl, TheDecl->getReturnType ())) {
30093016 // The CF attributes aren't represented in the type, so we need
30103017 // to check them here.
@@ -3109,15 +3116,19 @@ static CanSILFunctionType getSILFunctionTypeForClangDecl(
31093116 }
31103117
31113118 if (auto method = dyn_cast<clang::CXXMethodDecl>(clangDecl)) {
3112- AbstractionPattern origPattern = AbstractionPattern::getCXXMethod (origType, method,
3113- foreignInfo.self );
3114- bool isMutating =
3115- TC.Context .getClangModuleLoader ()->isCXXMethodMutating (method);
3116- auto conventions = CXXMethodConventions (method, isMutating);
3117- return getSILFunctionType (TC, TypeExpansionContext::minimal (), origPattern,
3118- substInterfaceType, extInfoBuilder, conventions,
3119- foreignInfo, constant, constant, None,
3120- ProtocolConformanceRef ());
3119+ // Static methods and ctors should be lowered like plane functions
3120+ // (case below).
3121+ if (!isa<clang::CXXConstructorDecl>(method) || method->isStatic ()) {
3122+ AbstractionPattern origPattern = AbstractionPattern::getCXXMethod (origType, method,
3123+ foreignInfo.self );
3124+ bool isMutating =
3125+ TC.Context .getClangModuleLoader ()->isCXXMethodMutating (method);
3126+ auto conventions = CXXMethodConventions (method, isMutating);
3127+ return getSILFunctionType (TC, TypeExpansionContext::minimal (), origPattern,
3128+ substInterfaceType, extInfoBuilder, conventions,
3129+ foreignInfo, constant, constant, None,
3130+ ProtocolConformanceRef ());
3131+ }
31213132 }
31223133
31233134 if (auto func = dyn_cast<clang::FunctionDecl>(clangDecl)) {
0 commit comments