mboehme created this revision.
mboehme added a project: clang.
Herald added a subscriber: cfe-commits.

These are needed for C++ interop in Swift. See this Swift forum discussion for 
details:

https://forums.swift.org/t/calling-c-constructors-looking-for-feedback-on-my-approach/34787/4?u=mboehme


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79486

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenABITypes.cpp
  clang/lib/CodeGen/CodeGenTypes.h

Index: clang/lib/CodeGen/CodeGenTypes.h
===================================================================
--- clang/lib/CodeGen/CodeGenTypes.h
+++ clang/lib/CodeGen/CodeGenTypes.h
@@ -244,11 +244,22 @@
                                                   unsigned ExtraPrefixArgs,
                                                   unsigned ExtraSuffixArgs,
                                                   bool PassProtoArgs = true);
+  const CGFunctionInfo &
+  arrangeCXXConstructorCall(ArrayRef<CanQualType> ArgTypes,
+                            const CXXConstructorDecl *D,
+                            CXXCtorType CtorKind,
+                            unsigned ExtraPrefixArgs,
+                            unsigned ExtraSuffixArgs,
+                            bool PassProtoArgs = true);
 
   const CGFunctionInfo &arrangeCXXMethodCall(const CallArgList &args,
                                              const FunctionProtoType *type,
                                              RequiredArgs required,
                                              unsigned numPrefixArgs);
+  const CGFunctionInfo &arrangeCXXMethodCall(ArrayRef<CanQualType> argTypes,
+                                             const FunctionProtoType *type,
+                                             RequiredArgs required,
+                                             unsigned numPrefixArgs);
   const CGFunctionInfo &
   arrangeUnprototypedMustTailThunk(const CXXMethodDecl *MD);
   const CGFunctionInfo &arrangeMSCtorClosure(const CXXConstructorDecl *CD,
Index: clang/lib/CodeGen/CodeGenABITypes.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenABITypes.cpp
+++ clang/lib/CodeGen/CodeGenABITypes.cpp
@@ -63,6 +63,27 @@
       info, {}, args);
 }
 
+const CGFunctionInfo &
+CodeGen::arrangeCXXConstructorCall(CodeGenModule &CGM,
+                                   ArrayRef<CanQualType> argTypes,
+                                   const CXXConstructorDecl *CD,
+                                   CXXCtorType CtorKind,
+                                   unsigned ExtraPrefixArgs,
+                                   unsigned ExtraSuffixArgs,
+                                   bool PassProtoArgs) {
+  return CGM.getTypes().arrangeCXXConstructorCall(
+      argTypes, CD, CtorKind, ExtraPrefixArgs, ExtraSuffixArgs, PassProtoArgs);
+}
+
+const CGFunctionInfo &arrangeCXXMethodCall(CodeGenModule &CGM,
+                                           ArrayRef<CanQualType> argTypes,
+                                           const FunctionProtoType *type,
+                                           RequiredArgs required,
+                                           unsigned numPrefixArgs) {
+  return CGM.getTypes().arrangeCXXMethodCall(argTypes, type, required,
+                                             numPrefixArgs);
+}
+
 llvm::FunctionType *
 CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) {
   assert(FD != nullptr && "Expected a non-null function declaration!");
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -399,6 +399,17 @@
   for (const auto &Arg : args)
     ArgTypes.push_back(Context.getCanonicalParamType(Arg.Ty));
 
+  return arrangeCXXConstructorCall(ArgTypes, D, CtorKind, ExtraPrefixArgs,
+                                   ExtraSuffixArgs, PassProtoArgs);
+}
+
+const CGFunctionInfo &
+CodeGenTypes::arrangeCXXConstructorCall(ArrayRef<CanQualType> ArgTypes,
+                                        const CXXConstructorDecl *D,
+                                        CXXCtorType CtorKind,
+                                        unsigned ExtraPrefixArgs,
+                                        unsigned ExtraSuffixArgs,
+                                        bool PassProtoArgs) {
   // +1 for implicit this, which should always be args[0].
   unsigned TotalPrefixArgs = 1 + ExtraPrefixArgs;
 
@@ -677,15 +688,23 @@
                                    const FunctionProtoType *proto,
                                    RequiredArgs required,
                                    unsigned numPrefixArgs) {
-  assert(numPrefixArgs + 1 <= args.size() &&
+  // FIXME: Kill copy.
+  auto argTypes = getArgTypesForCall(Context, args);
+
+  return arrangeCXXMethodCall(argTypes, proto, required, numPrefixArgs);
+}
+
+const CGFunctionInfo &
+CodeGenTypes::arrangeCXXMethodCall(ArrayRef<CanQualType> argTypes,
+                                   const FunctionProtoType *proto,
+                                   RequiredArgs required,
+                                   unsigned numPrefixArgs) {
+  assert(numPrefixArgs + 1 <= argTypes.size() &&
          "Emitting a call with less args than the required prefix?");
   // Add one to account for `this`. It's a bit awkward here, but we don't count
   // `this` in similar places elsewhere.
   auto paramInfos =
-    getExtParameterInfosForCall(proto, numPrefixArgs + 1, args.size());
-
-  // FIXME: Kill copy.
-  auto argTypes = getArgTypesForCall(Context, args);
+    getExtParameterInfosForCall(proto, numPrefixArgs + 1, argTypes.size());
 
   FunctionType::ExtInfo info = proto->getExtInfo();
   return arrangeLLVMFunctionInfo(
Index: clang/include/clang/CodeGen/CodeGenABITypes.h
===================================================================
--- clang/include/clang/CodeGen/CodeGenABITypes.h
+++ clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -25,6 +25,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/ABI.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
 
 namespace llvm {
@@ -38,6 +39,7 @@
 
 namespace clang {
 class ASTContext;
+class CXXConstructorDecl;
 class CXXRecordDecl;
 class CXXMethodDecl;
 class CodeGenOptions;
@@ -73,6 +75,20 @@
                                               FunctionType::ExtInfo info,
                                               RequiredArgs args);
 
+const CGFunctionInfo &arrangeCXXConstructorCall(CodeGenModule &CGM,
+                                                ArrayRef<CanQualType> argTypes,
+                                                const CXXConstructorDecl *CD,
+                                                CXXCtorType CtorKind,
+                                                unsigned ExtraPrefixArgs,
+                                                unsigned ExtraSuffixArgs,
+                                                bool PassProtoArgs = true);
+
+const CGFunctionInfo &arrangeCXXMethodCall(CodeGenModule &CGM,
+                                           ArrayRef<CanQualType> argTypes,
+                                           const FunctionProtoType *type,
+                                           RequiredArgs required,
+                                           unsigned numPrefixArgs);
+
 /// Returns null if the function type is incomplete and can't be lowered.
 llvm::FunctionType *convertFreeFunctionType(CodeGenModule &CGM,
                                             const FunctionDecl *FD);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D79486: [clang] Make... Martin Böhme via Phabricator via cfe-commits

Reply via email to