@@ -60,6 +60,13 @@ CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
6060 return *this ;
6161}
6262
63+ // / Returns the canonical formal type of the given C++ method.
64+ static CanQual<FunctionProtoType> getFormalType (const CXXMethodDecl *md) {
65+ return md->getType ()
66+ ->getCanonicalTypeUnqualified ()
67+ .getAs <FunctionProtoType>();
68+ }
69+
6370// / Adds the formal parameters in FPT to the given prefix. If any parameter in
6471// / FPT has pass_object_size_attrs, then we'll add parameters for those, too.
6572// / TODO(cir): this should be shared with LLVM codegen
@@ -76,6 +83,48 @@ static void appendParameterTypes(const CIRGenTypes &cgt,
7683 cgt.getCGModule ().errorNYI (" appendParameterTypes: hasExtParameterInfos" );
7784}
7885
86+ const CIRGenFunctionInfo &
87+ CIRGenTypes::arrangeCXXStructorDeclaration (GlobalDecl gd) {
88+ auto *md = cast<CXXMethodDecl>(gd.getDecl ());
89+
90+ llvm::SmallVector<CanQualType, 16 > argTypes;
91+ argTypes.push_back (deriveThisType (md->getParent (), md));
92+
93+ bool passParams = true ;
94+
95+ if (auto *cd = dyn_cast<CXXConstructorDecl>(md)) {
96+ // A base class inheriting constructor doesn't get forwarded arguments
97+ // needed to construct a virtual base (or base class thereof)
98+ if (cd->getInheritedConstructor ())
99+ cgm.errorNYI (cd->getSourceRange (),
100+ " arrangeCXXStructorDeclaration: inheriting constructor" );
101+ }
102+
103+ CanQual<FunctionProtoType> fpt = getFormalType (md);
104+
105+ if (passParams)
106+ appendParameterTypes (*this , argTypes, fpt);
107+
108+ assert (!cir::MissingFeatures::implicitConstructorArgs ());
109+
110+ RequiredArgs required =
111+ (passParams && md->isVariadic () ? RequiredArgs (argTypes.size ())
112+ : RequiredArgs::All);
113+
114+ CanQualType resultType = theCXXABI.hasThisReturn (gd) ? argTypes.front ()
115+ : theCXXABI.hasMostDerivedReturn (gd)
116+ ? astContext.VoidPtrTy
117+ : astContext.VoidTy ;
118+
119+ assert (!theCXXABI.hasThisReturn (gd) &&
120+ " Please send PR with a test and remove this" );
121+
122+ assert (!cir::MissingFeatures::opCallCIRGenFuncInfoExtParamInfo ());
123+ assert (!cir::MissingFeatures::opCallFnInfoOpts ());
124+
125+ return arrangeCIRFunctionInfo (resultType, argTypes, required);
126+ }
127+
79128// / Derives the 'this' type for CIRGen purposes, i.e. ignoring method CVR
80129// / qualification. Either or both of `rd` and `md` may be null. A null `rd`
81130// / indicates that there is no meaningful 'this' type, and a null `md` can occur
@@ -103,13 +152,13 @@ CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd,
103152// / top of any implicit parameters already stored.
104153static const CIRGenFunctionInfo &
105154arrangeCIRFunctionInfo (CIRGenTypes &cgt, SmallVectorImpl<CanQualType> &prefix,
106- CanQual<FunctionProtoType> ftp ) {
155+ CanQual<FunctionProtoType> fpt ) {
107156 assert (!cir::MissingFeatures::opCallFnInfoOpts ());
108157 RequiredArgs required =
109- RequiredArgs::getFromProtoWithExtraSlots (ftp , prefix.size ());
158+ RequiredArgs::getFromProtoWithExtraSlots (fpt , prefix.size ());
110159 assert (!cir::MissingFeatures::opCallExtParameterInfo ());
111- appendParameterTypes (cgt, prefix, ftp );
112- CanQualType resultType = ftp ->getReturnType ().getUnqualifiedType ();
160+ appendParameterTypes (cgt, prefix, fpt );
161+ CanQualType resultType = fpt ->getReturnType ().getUnqualifiedType ();
113162 return cgt.arrangeCIRFunctionInfo (resultType, prefix, required);
114163}
115164
@@ -141,6 +190,44 @@ arrangeFreeFunctionLikeCall(CIRGenTypes &cgt, CIRGenModule &cgm,
141190 return cgt.arrangeCIRFunctionInfo (retType, argTypes, required);
142191}
143192
193+ // / Arrange a call to a C++ method, passing the given arguments.
194+ // /
195+ // / passProtoArgs indicates whether `args` has args for the parameters in the
196+ // / given CXXConstructorDecl.
197+ const CIRGenFunctionInfo &CIRGenTypes::arrangeCXXConstructorCall (
198+ const CallArgList &args, const CXXConstructorDecl *d, CXXCtorType ctorKind,
199+ bool passProtoArgs) {
200+
201+ // FIXME: Kill copy.
202+ llvm::SmallVector<CanQualType, 16 > argTypes;
203+ for (const auto &arg : args)
204+ argTypes.push_back (astContext.getCanonicalParamType (arg.ty ));
205+
206+ assert (!cir::MissingFeatures::implicitConstructorArgs ());
207+ // +1 for implicit this, which should always be args[0]
208+ unsigned totalPrefixArgs = 1 ;
209+
210+ CanQual<FunctionProtoType> fpt = getFormalType (d);
211+ RequiredArgs required =
212+ passProtoArgs
213+ ? RequiredArgs::getFromProtoWithExtraSlots (fpt, totalPrefixArgs)
214+ : RequiredArgs::All;
215+
216+ GlobalDecl gd (d, ctorKind);
217+ if (theCXXABI.hasThisReturn (gd))
218+ cgm.errorNYI (d->getSourceRange (),
219+ " arrangeCXXConstructorCall: hasThisReturn" );
220+ if (theCXXABI.hasMostDerivedReturn (gd))
221+ cgm.errorNYI (d->getSourceRange (),
222+ " arrangeCXXConstructorCall: hasMostDerivedReturn" );
223+ CanQualType resultType = astContext.VoidTy ;
224+
225+ assert (!cir::MissingFeatures::opCallFnInfoOpts ());
226+ assert (!cir::MissingFeatures::opCallCIRGenFuncInfoExtParamInfo ());
227+
228+ return arrangeCIRFunctionInfo (resultType, argTypes, required);
229+ }
230+
144231// / Arrange a call to a C++ method, passing the given arguments.
145232// /
146233// / numPrefixArgs is the number of the ABI-specific prefix arguments we have. It
@@ -198,7 +285,7 @@ CIRGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *md) {
198285// / constructor or destructor.
199286const CIRGenFunctionInfo &
200287CIRGenTypes::arrangeCXXMethodType (const CXXRecordDecl *rd,
201- const FunctionProtoType *ftp ,
288+ const FunctionProtoType *fpt ,
202289 const CXXMethodDecl *md) {
203290 llvm::SmallVector<CanQualType, 16 > argTypes;
204291
@@ -208,7 +295,7 @@ CIRGenTypes::arrangeCXXMethodType(const CXXRecordDecl *rd,
208295 assert (!cir::MissingFeatures::opCallFnInfoOpts ());
209296 return ::arrangeCIRFunctionInfo (
210297 *this , argTypes,
211- ftp ->getCanonicalTypeUnqualified ().getAs <FunctionProtoType>());
298+ fpt ->getCanonicalTypeUnqualified ().getAs <FunctionProtoType>());
212299}
213300
214301// / Arrange the argument and result information for the declaration or
0 commit comments