compnerd updated this revision to Diff 132528.
compnerd added a comment.

Handle the non-top-level decl case


Repository:
  rC Clang

https://reviews.llvm.org/D42768

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/msabi-swiftcall-cc.cpp

Index: test/CodeGenCXX/msabi-swiftcall-cc.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/msabi-swiftcall-cc.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fdeclspec -emit-llvm %s -o - | FileCheck %s
+
+void __attribute__((__swiftcall__)) f() {}
+// CHECK-DAG: @"\01?f@__swift_cc@__Swift@@YAXXZ"
+
+void (__attribute__((__swiftcall__)) *p)();
+// CHECK-DAG: @"\01?p@@3P8__swift_cc@__Swift@@AAXXZA"
+
+namespace {
+void __attribute__((__swiftcall__)) __attribute__((__used__)) f() { }
+// CHECK-DAG: "\01?f@?A@__swift_cc@__Swift@@YAXXZ"
+}
+
+namespace n {
+void __attribute__((__swiftcall__)) f() {}
+// CHECK-DAG: "\01?f@n@__swift_cc@__Swift@@YAXXZ"
+}
+
+namespace __Swift { namespace __swift_cc {
+void __attribute__((__swiftcall__)) f() { }
+// CHECK-DAG: "\01?f@__swift_cc@__Swift@12@YAXXZ"
+} }
+
+struct __declspec(dllexport) S {
+  S(const S &) = delete;
+  S & operator=(const S &) = delete;
+  void __attribute__((__swiftcall__)) m() { }
+  // CHECK-DAG: "\01?m@S@__swift_cc@__Swift@@QAAXXZ"
+};
+
+void f(void (__attribute__((__swiftcall__))())) {}
+// CHECK-DAG: "\01?f@@YAXP8__swift_cc@__Swift@@AAXXZ@Z"
Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -953,8 +953,13 @@
 void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) {
   // <postfix> ::= <unqualified-name> [<postfix>]
   //           ::= <substitution> [<postfix>]
-  const DeclContext *DC = getEffectiveDeclContext(ND);
 
+  const Type *Ty = nullptr;
+
+  if (const auto *FD = dyn_cast<FunctionDecl>(ND))
+    Ty = FD->getType()->getAs<FunctionType>();
+
+  const DeclContext *DC = getEffectiveDeclContext(ND);
   while (!DC->isTranslationUnit()) {
     if (isa<TagDecl>(ND) || isa<VarDecl>(ND)) {
       unsigned Disc;
@@ -1050,6 +1055,11 @@
     }
     DC = DC->getParent();
   }
+
+  if (Ty)
+    if (Ty->getAs<FunctionType>()->getCallConv() == CC_Swift)
+      for (const char *NS : {"__swift_cc", "__Swift"})
+        mangleSourceName(NS);
 }
 
 void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
@@ -1702,8 +1712,16 @@
     break;
   case QMM_Mangle:
     if (const FunctionType *FT = dyn_cast<FunctionType>(T)) {
-      Out << '6';
-      mangleFunctionType(FT);
+      if (FT->getCallConv() == CC_Swift) {
+        Out << '8';
+        for (const char *NS : {"__swift_cc", "__Swift"})
+          mangleSourceName(NS);
+        Out << '@';
+        mangleFunctionType(FT, nullptr, true);
+      } else {
+        Out << '6';
+        mangleFunctionType(FT);
+      }
       return;
     }
     mangleQualifiers(Quals, false);
@@ -1959,6 +1977,11 @@
     mangleQualifiers(Quals, /*IsMember=*/false);
   }
 
+  // We currently mangle the SwiftCC as `__Swift::__swift_cc` namespace on the
+  // decl in mangleNestedName.
+  if (CC == CC_Swift)
+    CC = CC_C;
+
   mangleCallingConvention(CC);
 
   // <return-type> ::= <type>
@@ -2341,6 +2364,7 @@
 void MicrosoftCXXNameMangler::mangleType(const PointerType *T, Qualifiers Quals,
                                          SourceRange Range) {
   QualType PointeeType = T->getPointeeType();
+
   manglePointerCVQualifiers(Quals);
   manglePointerExtQualifiers(Quals, PointeeType);
   mangleType(PointeeType, Range);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to