[PATCH] D42768: AST: add an extension to support SwiftCC on MS ABI

Saleem Abdulrasool via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 14:56:47 PST 2018


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

address design changes


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,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__ at X@@XZ"
+
+void (__attribute__((__swiftcall__)) *p)();
+// CHECK-DAG: @"\01?p@@3P6AU?$__swiftcall__ at X@@XZA"
+
+namespace {
+void __attribute__((__swiftcall__)) __attribute__((__used__)) f() { }
+// CHECK-DAG: "\01?f@?A@@YAU?$__swiftcall__ at X@@XZ"
+}
+
+namespace n {
+void __attribute__((__swiftcall__)) f() {}
+// CHECK-DAG: "\01?f at n@@YAU?$__swiftcall__ at X@@XZ"
+}
+
+struct __declspec(dllexport) S {
+  S(const S &) = delete;
+  S & operator=(const S &) = delete;
+  void __attribute__((__swiftcall__)) m() { }
+  // CHECK-DAG: "\01?m at S@@QAAU?$__swiftcall__ at X@@XZ"
+};
+
+void f(void (__attribute__((__swiftcall__))())) {}
+// CHECK-DAG: "\01?f@@YAXP6AU?$__swiftcall__ at X@@XZ at Z"
+
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 @@
   }
 }

+// <postfix> ::= <unqualified-name> [<postfix>]
+//           ::= <substitution> [<postfix>]
 void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) {
-  // <postfix> ::= <unqualified-name> [<postfix>]
-  //           ::= <substitution> [<postfix>]
   const DeclContext *DC = getEffectiveDeclContext(ND);
-
   while (!DC->isTranslationUnit()) {
     if (isa<TagDecl>(ND) || isa<VarDecl>(ND)) {
       unsigned Disc;
@@ -1959,7 +1969,7 @@
     mangleQualifiers(Quals, /*IsMember=*/false);
   }

-  mangleCallingConvention(CC);
+  mangleCallingConvention(CC == CC_Swift ? CC_C : CC);

   // <return-type> ::= <type>
   //               ::= @ # 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);
     }
   }



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42768.133087.patch
Type: text/x-patch
Size: 2892 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180206/2a5b83c1/attachment-0001.bin>


More information about the cfe-commits mailing list