[clang] 44f7929 - [Demangle] Support demangling Swift calling convention in MS demangler.

2021-01-27 Thread Varun Gandhi via cfe-commits

Author: Varun Gandhi
Date: 2021-01-27T13:24:54-08:00
New Revision: 44f792966e0f2935ea9e0ce96a4f35e01bfe6b61

URL: 
https://github.com/llvm/llvm-project/commit/44f792966e0f2935ea9e0ce96a4f35e01bfe6b61
DIFF: 
https://github.com/llvm/llvm-project/commit/44f792966e0f2935ea9e0ce96a4f35e01bfe6b61.diff

LOG: [Demangle] Support demangling Swift calling convention in MS demangler.

Previously, Clang was able to mangle the Swift calling
convention but 'MicrosoftDemangle.cpp' was not able to demangle it.

Reviewed By: compnerd, rnk

Differential Revision: https://reviews.llvm.org/D95053

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
llvm/lib/Demangle/MicrosoftDemangle.cpp
llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
llvm/test/Demangle/ms-mangle.test

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index df6c566abc7d..9eac3586c871 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2684,6 +2684,7 @@ void 
MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //  ::= w # __regcall
   // The 'export' calling conventions are from a bygone era
   // (*cough*Win16*cough*) when functions were declared for export with

diff  --git a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h 
b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
index 62e0f4765a69..bcc63b6ef5cb 100644
--- a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@ enum class CallingConv : uint8_t {
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };

diff  --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp 
b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index 16074314a84d..2596eed71e23 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@ CallingConv 
Demangler::demangleCallingConvention(StringView &MangledName) {
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;

diff  --git a/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp 
b/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
index 8b15ffcee778..0a3ba6d69ac9 100644
--- a/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@ static void outputCallingConvention(OutputStream &OS, 
CallingConv CC) {
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__)) ";
+break;
   default:
 break;
   }

diff  --git a/llvm/test/Demangle/ms-mangle.test 
b/llvm/test/Demangle/ms-mangle.test
index bbac3ebb9971..c77802ca0e85 100644
--- a/llvm/test/Demangle/ms-mangle.test
+++ b/llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 44f7929 - [Demangle] Support demangling Swift calling convention in MS demangler.

2021-01-27 Thread Varun Gandhi via cfe-commits

Author: Varun Gandhi
Date: 2021-01-27T13:24:54-08:00
New Revision: 44f792966e0f2935ea9e0ce96a4f35e01bfe6b61

URL: 
https://github.com/llvm/llvm-project/commit/44f792966e0f2935ea9e0ce96a4f35e01bfe6b61
DIFF: 
https://github.com/llvm/llvm-project/commit/44f792966e0f2935ea9e0ce96a4f35e01bfe6b61.diff

LOG: [Demangle] Support demangling Swift calling convention in MS demangler.

Previously, Clang was able to mangle the Swift calling
convention but 'MicrosoftDemangle.cpp' was not able to demangle it.

Reviewed By: compnerd, rnk

Differential Revision: https://reviews.llvm.org/D95053

Added: 


Modified: 
clang/lib/AST/MicrosoftMangle.cpp
llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
llvm/lib/Demangle/MicrosoftDemangle.cpp
llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
llvm/test/Demangle/ms-mangle.test

Removed: 




diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index df6c566abc7d..9eac3586c871 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -2684,6 +2684,7 @@ void 
MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //  ::= w # __regcall
   // The 'export' calling conventions are from a bygone era
   // (*cough*Win16*cough*) when functions were declared for export with

diff  --git a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h 
b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
index 62e0f4765a69..bcc63b6ef5cb 100644
--- a/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ b/llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@ enum class CallingConv : uint8_t {
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };

diff  --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp 
b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index 16074314a84d..2596eed71e23 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@ CallingConv 
Demangler::demangleCallingConvention(StringView &MangledName) {
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;

diff  --git a/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp 
b/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
index 8b15ffcee778..0a3ba6d69ac9 100644
--- a/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@ static void outputCallingConvention(OutputStream &OS, 
CallingConv CC) {
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__)) ";
+break;
   default:
 break;
   }

diff  --git a/llvm/test/Demangle/ms-mangle.test 
b/llvm/test/Demangle/ms-mangle.test
index bbac3ebb9971..c77802ca0e85 100644
--- a/llvm/test/Demangle/ms-mangle.test
+++ b/llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 92dcb1d - [Clang] Introduce Swift async calling convention.

2021-07-09 Thread Varun Gandhi via cfe-commits

Author: Varun Gandhi
Date: 2021-07-09T11:50:10-07:00
New Revision: 92dcb1d2db8c4de48df0af806dca631523cd4169

URL: 
https://github.com/llvm/llvm-project/commit/92dcb1d2db8c4de48df0af806dca631523cd4169
DIFF: 
https://github.com/llvm/llvm-project/commit/92dcb1d2db8c4de48df0af806dca631523cd4169.diff

LOG: [Clang] Introduce Swift async calling convention.

This change is intended as initial setup. The plan is to add
more semantic checks later. I plan to update the documentation
as more semantic checks are added (instead of documenting the
details up front). Most of the code closely mirrors that for
the Swift calling convention. Three places are marked as
[FIXME: swiftasynccc]; those will be addressed once the
corresponding convention is introduced in LLVM.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D95561

Added: 
clang/test/CodeGen/swift-async-call-conv.c

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/Features.def
clang/include/clang/Basic/Specifiers.h
clang/include/clang/CodeGen/SwiftCallingConv.h
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/PPC.h
clang/lib/Basic/Targets/SystemZ.h
clang/lib/Basic/Targets/WebAssembly.h
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/64bit-swiftcall.c
clang/test/CodeGen/arm-swiftcall.c
clang/test/CodeGen/debug-info-cc.c
clang/test/CodeGen/swift-call-conv.c
clang/test/Sema/attr-c2x.c
clang/test/Sema/attr-swiftcall.c
clang/test/Sema/no_callconv.cpp
clang/test/SemaCXX/attr-swiftcall.cpp
clang/tools/libclang/CXType.cpp
llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
llvm/lib/Demangle/MicrosoftDemangle.cpp
llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
llvm/lib/Transforms/IPO/MergeFunctions.cpp
llvm/test/Demangle/ms-mangle.test

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index c7d3b4e10622..26844d1c74f3 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -33,7 +33,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 61
+#define CINDEX_VERSION_MINOR 62
 
 #define CINDEX_VERSION_ENCODE(major, minor) (((major)*1) + ((minor)*1))
 
@@ -3418,6 +3418,7 @@ enum CXCallingConv {
   CXCallingConv_PreserveMost = 14,
   CXCallingConv_PreserveAll = 15,
   CXCallingConv_AArch64VectorCall = 16,
+  CXCallingConv_SwiftAsync = 17,
 
   CXCallingConv_Invalid = 100,
   CXCallingConv_Unexposed = 200

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bfcf5f798d8f..e27efd404c21 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2459,6 +2459,11 @@ def SwiftCall : DeclOrTypeAttr {
   let Documentation = [SwiftCallDocs];
 }
 
+def SwiftAsyncCall : DeclOrTypeAttr {
+  let Spellings = [Clang<"swiftasynccall">];
+  let Documentation = [SwiftAsyncCallDocs];
+}
+
 def SwiftContext : ParameterABIAttr {
   let Spellings = [Clang<"swift_context">];
   let Documentation = [SwiftContextDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index bf51b05acaaa..0a665fee7686 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4527,7 +4527,8 @@ def SwiftContextDocs : Documentation {
   let Category = DocCatVariable;
   let Content = [{
 The ``swift_context`` attribute marks a parameter of a ``swiftcall``
-function as having the special context-parameter ABI treatment.
+or ``swiftasynccall`` function as having the special context-parameter
+ABI treatment.
 
 This treatment generally passes the context value in a special register
 which is normally callee-preserved.
@@ -4540,14 +4541,39 @@ A context parameter must have pointer or reference type.
   }];
 }
 
+def SwiftAsyncCallDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``swiftasynccall`` attribute indicates that a function is
+compatible with the low-level conventions of Swift async functions,
+provided it declares the right formal arguments.
+
+In most respects, this is similar to the ``swiftcall`` attribute, except for
+the following:
+- A parameter may be marked ``swift_async_context``, ``swift_context``
+  or ``swift_indirect_result`` (with the same rest

[clang] 37e83bc - [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy

2021-01-06 Thread Varun Gandhi via cfe-commits

Author: Varun Gandhi
Date: 2021-01-06T16:44:50-08:00
New Revision: 37e83bc6db3ad7d9a5d182694ebe71ebbc6120de

URL: 
https://github.com/llvm/llvm-project/commit/37e83bc6db3ad7d9a5d182694ebe71ebbc6120de
DIFF: 
https://github.com/llvm/llvm-project/commit/37e83bc6db3ad7d9a5d182694ebe71ebbc6120de.diff

LOG: [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy

The implementation for (de)serialization of APValues can be shared
between Clang and Swift, so we prefer pushing the methods up
the inheritance hierarchy, instead of having the methods live in
ASTReader/ASTWriter. Fixes rdar://72592937.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D94196

Added: 


Modified: 
clang/include/clang/AST/APValue.h
clang/include/clang/AST/AbstractBasicReader.h
clang/include/clang/AST/AbstractBasicWriter.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/Serialization/ASTRecordReader.h
clang/include/clang/Serialization/ASTRecordWriter.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/AST/APValue.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/utils/TableGen/ClangASTPropertiesEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index eded34808ad7..f9b189926c76 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -23,6 +23,10 @@
 #include "llvm/Support/AlignOf.h"
 
 namespace clang {
+namespace serialization {
+template  class BasicReaderBase;
+} // end namespace serialization
+
   class AddrLabelExpr;
   class ASTContext;
   class CharUnits;
@@ -233,12 +237,20 @@ class APValue {
   return llvm::hash_value(A.Value);
 }
   };
+  class LValuePathSerializationHelper {
+const void *ElemTy;
+
+  public:
+ArrayRef Path;
+
+LValuePathSerializationHelper(ArrayRef, QualType);
+QualType getType();
+  };
   struct NoLValuePath {};
   struct UninitArray {};
   struct UninitStruct {};
 
-  friend class ASTRecordReader;
-  friend class ASTWriter;
+  template  friend class clang::serialization::BasicReaderBase;
   friend class ASTImporter;
   friend class ASTNodeImporter;
 

diff  --git a/clang/include/clang/AST/AbstractBasicReader.h 
b/clang/include/clang/AST/AbstractBasicReader.h
index d7b3a9da88ec..5505d661b44e 100644
--- a/clang/include/clang/AST/AbstractBasicReader.h
+++ b/clang/include/clang/AST/AbstractBasicReader.h
@@ -177,6 +177,40 @@ class DataStreamBasicReader : public BasicReaderBase 
{
 return llvm::APInt(bitWidth, numWords, &data[0]);
   }
 
+  llvm::FixedPointSemantics readFixedPointSemantics() {
+unsigned width = asImpl().readUInt32();
+unsigned scale = asImpl().readUInt32();
+unsigned tmp = asImpl().readUInt32();
+bool isSigned = tmp & 0x1;
+bool isSaturated = tmp & 0x2;
+bool hasUnsignedPadding = tmp & 0x4;
+return llvm::FixedPointSemantics(width, scale, isSigned, isSaturated,
+ hasUnsignedPadding);
+  }
+
+  APValue::LValuePathSerializationHelper readLValuePathSerializationHelper(
+  SmallVectorImpl &path) {
+auto elemTy = asImpl().readQualType();
+unsigned pathLength = asImpl().readUInt32();
+for (unsigned i = 0; i < pathLength; ++i) {
+  if (elemTy->template getAs()) {
+unsigned int_ = asImpl().readUInt32();
+Decl *decl = asImpl().template readDeclAs();
+if (auto *recordDecl = dyn_cast(decl))
+  elemTy = getASTContext().getRecordType(recordDecl);
+else
+  elemTy = cast(decl)->getType();
+path.push_back(
+APValue::LValuePathEntry(APValue::BaseOrMemberType(decl, int_)));
+  } else {
+elemTy = getASTContext().getAsArrayType(elemTy)->getElementType();
+path.push_back(
+APValue::LValuePathEntry::ArrayIndex(asImpl().readUInt32()));
+  }
+}
+return APValue::LValuePathSerializationHelper(path, elemTy);
+  }
+
   Qualifiers readQualifiers() {
 static_assert(sizeof(Qualifiers().getAsOpaqueValue()) <= sizeof(uint32_t),
   "update this if the value size changes");

diff  --git a/clang/include/clang/AST/AbstractBasicWriter.h 
b/clang/include/clang/AST/AbstractBasicWriter.h
index 0a6730c86bbf..75aef734ba9b 100644
--- a/clang/include/clang/AST/AbstractBasicWriter.h
+++ b/clang/include/clang/AST/AbstractBasicWriter.h
@@ -9,6 +9,7 @@
 #ifndef CLANG_AST_ABSTRACTBASICWRITER_H
 #define CLANG_AST_ABSTRACTBASICWRITER_H
 
+#include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclTemplate.h"
 
 namespace clang {
@@ -121,6 +122,7 @@ template 
 class DataStreamBasicWriter : public BasicWriterBase {
 protected:
   using BasicWriterBase::asImpl;
+  DataStreamBasicWriter(ASTContext &ctx) : BasicWriterBase(ctx) {}
 
 public:
   /// Implement property-find by ignoring it.  We rely on properties