@@ -60,6 +60,13 @@ CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
60
60
return *this ;
61
61
}
62
62
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
+
63
70
// / Adds the formal parameters in FPT to the given prefix. If any parameter in
64
71
// / FPT has pass_object_size_attrs, then we'll add parameters for those, too.
65
72
// / TODO(cir): this should be shared with LLVM codegen
@@ -76,6 +83,48 @@ static void appendParameterTypes(const CIRGenTypes &cgt,
76
83
cgt.getCGModule ().errorNYI (" appendParameterTypes: hasExtParameterInfos" );
77
84
}
78
85
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
+
79
128
// / Derives the 'this' type for CIRGen purposes, i.e. ignoring method CVR
80
129
// / qualification. Either or both of `rd` and `md` may be null. A null `rd`
81
130
// / indicates that there is no meaningful 'this' type, and a null `md` can occur
@@ -103,13 +152,13 @@ CanQualType CIRGenTypes::deriveThisType(const CXXRecordDecl *rd,
103
152
// / top of any implicit parameters already stored.
104
153
static const CIRGenFunctionInfo &
105
154
arrangeCIRFunctionInfo (CIRGenTypes &cgt, SmallVectorImpl<CanQualType> &prefix,
106
- CanQual<FunctionProtoType> ftp ) {
155
+ CanQual<FunctionProtoType> fpt ) {
107
156
assert (!cir::MissingFeatures::opCallFnInfoOpts ());
108
157
RequiredArgs required =
109
- RequiredArgs::getFromProtoWithExtraSlots (ftp , prefix.size ());
158
+ RequiredArgs::getFromProtoWithExtraSlots (fpt , prefix.size ());
110
159
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 ();
113
162
return cgt.arrangeCIRFunctionInfo (resultType, prefix, required);
114
163
}
115
164
@@ -141,6 +190,44 @@ arrangeFreeFunctionLikeCall(CIRGenTypes &cgt, CIRGenModule &cgm,
141
190
return cgt.arrangeCIRFunctionInfo (retType, argTypes, required);
142
191
}
143
192
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
+
144
231
// / Arrange a call to a C++ method, passing the given arguments.
145
232
// /
146
233
// / numPrefixArgs is the number of the ABI-specific prefix arguments we have. It
@@ -198,7 +285,7 @@ CIRGenTypes::arrangeCXXMethodDeclaration(const CXXMethodDecl *md) {
198
285
// / constructor or destructor.
199
286
const CIRGenFunctionInfo &
200
287
CIRGenTypes::arrangeCXXMethodType (const CXXRecordDecl *rd,
201
- const FunctionProtoType *ftp ,
288
+ const FunctionProtoType *fpt ,
202
289
const CXXMethodDecl *md) {
203
290
llvm::SmallVector<CanQualType, 16 > argTypes;
204
291
@@ -208,7 +295,7 @@ CIRGenTypes::arrangeCXXMethodType(const CXXRecordDecl *rd,
208
295
assert (!cir::MissingFeatures::opCallFnInfoOpts ());
209
296
return ::arrangeCIRFunctionInfo (
210
297
*this , argTypes,
211
- ftp ->getCanonicalTypeUnqualified ().getAs <FunctionProtoType>());
298
+ fpt ->getCanonicalTypeUnqualified ().getAs <FunctionProtoType>());
212
299
}
213
300
214
301
// / Arrange the argument and result information for the declaration or
0 commit comments