@@ -119,20 +119,13 @@ static auto IsSimpleAbiType(clang::ASTContext& ast_context,
119
119
return false ;
120
120
}
121
121
122
- // Creates the thunk parameter types given the callee function. Also returns for
123
- // each type whether it is different from the matching callee function parameter
124
- // type.
122
+ // Creates the thunk parameter types given the callee function.
125
123
static auto BuildThunkParameterTypes (
126
124
clang::ASTContext& ast_context,
127
125
const clang::FunctionDecl& callee_function_decl)
128
- -> std::tuple<llvm::SmallVector<clang::QualType>, llvm::SmallVector<bool>> {
129
- std::tuple<llvm::SmallVector<clang::QualType>, llvm::SmallVector<bool >>
130
- result;
131
- auto & [thunk_param_types, param_type_changed] = result;
132
-
133
- unsigned num_params = callee_function_decl.getNumParams ();
134
- thunk_param_types.reserve (num_params);
135
- param_type_changed.reserve (num_params);
126
+ -> llvm::SmallVector<clang::QualType> {
127
+ llvm::SmallVector<clang::QualType> thunk_param_types;
128
+ thunk_param_types.reserve (callee_function_decl.getNumParams ());
136
129
137
130
for (const clang::ParmVarDecl* callee_param :
138
131
callee_function_decl.parameters ()) {
@@ -143,11 +136,10 @@ static auto BuildThunkParameterTypes(
143
136
param_type = ast_context.getAttributedType (
144
137
clang::NullabilityKind::NonNull, pointer_type, pointer_type);
145
138
}
146
- param_type_changed.push_back (!is_simple_abi_type);
147
139
thunk_param_types.push_back (param_type);
148
140
}
149
141
150
- return result ;
142
+ return thunk_param_types ;
151
143
}
152
144
153
145
// Returns the thunk parameters using the callee function parameter identifiers.
@@ -225,19 +217,20 @@ static auto CreateThunkFunctionDecl(
225
217
// callee function which is the thunk parameter or its address.
226
218
static auto BuildCalleeArgs (clang::Sema& sema,
227
219
clang::FunctionDecl* thunk_function_decl,
228
- llvm::ArrayRef< bool > param_type_changed )
220
+ const clang::FunctionDecl& callee_function_decl )
229
221
-> llvm::SmallVector<clang::Expr*> {
230
222
llvm::SmallVector<clang::Expr*> call_args;
231
223
size_t num_params = thunk_function_decl->getNumParams ();
232
- CARBON_CHECK (param_type_changed. size () == num_params);
224
+ CARBON_CHECK (callee_function_decl. getNumParams () == num_params);
233
225
call_args.reserve (num_params);
234
226
for (unsigned i = 0 ; i < num_params; ++i) {
235
227
clang::ParmVarDecl* thunk_param = thunk_function_decl->getParamDecl (i);
236
228
clang::SourceLocation clang_loc = thunk_param->getLocation ();
237
229
238
230
clang::Expr* call_arg = sema.BuildDeclRefExpr (
239
231
thunk_param, thunk_param->getType (), clang::VK_LValue, clang_loc);
240
- if (param_type_changed[i]) {
232
+ if (thunk_param->getType () !=
233
+ callee_function_decl.getParamDecl (i)->getType ()) {
241
234
// TODO: Consider inserting a cast to an rvalue. Note that we currently
242
235
// pass pointers to non-temporary objects as the argument when calling a
243
236
// thunk, so we'll need to either change that or generate different thunks
@@ -288,7 +281,7 @@ auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
288
281
CARBON_CHECK (callee_function_decl);
289
282
290
283
// Build the thunk function declaration.
291
- auto [ thunk_param_types, param_type_changed] =
284
+ auto thunk_param_types =
292
285
BuildThunkParameterTypes (context.ast_context (), *callee_function_decl);
293
286
clang::FunctionDecl* thunk_function_decl = CreateThunkFunctionDecl (
294
287
context, *callee_function_decl, thunk_param_types);
@@ -299,7 +292,7 @@ auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
299
292
sema.ActOnStartOfFunctionDef (nullptr , thunk_function_decl);
300
293
301
294
llvm::SmallVector<clang::Expr*> call_args =
302
- BuildCalleeArgs (sema, thunk_function_decl, param_type_changed );
295
+ BuildCalleeArgs (sema, thunk_function_decl, *callee_function_decl );
303
296
clang::Stmt* body = BuildThunkBody (sema, callee_function_decl, call_args);
304
297
sema.ActOnFinishFunctionBody (thunk_function_decl, body);
305
298
if (!body) {
0 commit comments