Index: lib/AST/MicrosoftMangle.cpp =================================================================== --- lib/AST/MicrosoftMangle.cpp +++ lib/AST/MicrosoftMangle.cpp @@ -316,6 +316,17 @@ return ND == Structor || getStructor(ND) == Structor; } + void mangleSwiftCall(QualType T, SourceRange R, QualifierMangleMode QMM) { + llvm::SmallString<64> TemplateMangling; + llvm::raw_svector_ostream Stream(TemplateMangling); + MicrosoftCXXNameMangler Extra(Context, Stream); + + Stream << "?$"; + Extra.mangleSourceName("__swiftcall__"); + Extra.mangleType(T, R, QMM); + mangleArtificalTagType(TTK_Struct, TemplateMangling); + } + void mangleUnqualifiedName(const NamedDecl *ND) { mangleUnqualifiedName(ND, ND->getDeclName()); } @@ -950,11 +961,10 @@ } } +// ::= [] +// ::= [] void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) { - // ::= [] - // ::= [] const DeclContext *DC = getEffectiveDeclContext(ND); - while (!DC->isTranslationUnit()) { if (isa(ND) || isa(ND)) { unsigned Disc; @@ -1959,7 +1969,7 @@ mangleQualifiers(Quals, /*IsMember=*/false); } - mangleCallingConvention(CC); + mangleCallingConvention(CC == CC_Swift ? CC_C : CC); // ::= // ::= @ # structors (they have no declared return type) @@ -2017,7 +2027,10 @@ } else { if (ResultType->isVoidType()) ResultType = ResultType.getUnqualifiedType(); - mangleType(ResultType, Range, QMM_Result); + if (CC == CC_Swift) + mangleSwiftCall(ResultType, Range, QMM_Result); + else + mangleType(ResultType, Range, QMM_Result); } } Index: test/CodeGenCXX/msabi-swiftcall-cc.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/msabi-swiftcall-cc.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fdeclspec -emit-llvm %s -o - | FileCheck %s + +void __attribute__((__swiftcall__)) f() {} +// CHECK-DAG: @"\01?f@@YAU?$__swiftcall__@X@@XZ" + +void (__attribute__((__swiftcall__)) *p)(); +// CHECK-DAG: @"\01?p@@3P6AU?$__swiftcall__@X@@XZA" + +namespace { +void __attribute__((__swiftcall__)) __attribute__((__used__)) f() { } +// CHECK-DAG: "\01?f@?A@@YAU?$__swiftcall__@X@@XZ" +} + +namespace n { +void __attribute__((__swiftcall__)) f() {} +// CHECK-DAG: "\01?f@n@@YAU?$__swiftcall__@X@@XZ" +} + +struct __declspec(dllexport) S { + S(const S &) = delete; + S & operator=(const S &) = delete; + void __attribute__((__swiftcall__)) m() { } + // CHECK-DAG: "\01?m@S@@QAAU?$__swiftcall__@X@@XZ" +}; + +void f(void (__attribute__((__swiftcall__))())) {} +// CHECK-DAG: "\01?f@@YAXP6AU?$__swiftcall__@X@@XZ@Z" +