|
10 | 10 | #include "toolchain/check/context.h"
|
11 | 11 | #include "toolchain/check/control_flow.h"
|
12 | 12 | #include "toolchain/check/convert.h"
|
| 13 | +#include "toolchain/check/cpp_thunk.h" |
13 | 14 | #include "toolchain/check/deduce.h"
|
14 | 15 | #include "toolchain/check/facet_type.h"
|
15 | 16 | #include "toolchain/check/function.h"
|
@@ -255,27 +256,39 @@ static auto PerformCallToFunction(Context& context, SemIR::LocId loc_id,
|
255 | 256 | ConvertCallArgs(context, loc_id, callee_function.self_id, arg_ids,
|
256 | 257 | return_slot_arg_id, callee, *callee_specific_id);
|
257 | 258 |
|
258 |
| - // If we're about to form a direct call to a thunk, inline it. |
259 |
| - if (callee.special_function_kind == |
260 |
| - SemIR::Function::SpecialFunctionKind::Thunk) { |
261 |
| - LoadImportRef(context, callee.thunk_decl_id()); |
| 259 | + switch (callee.special_function_kind) { |
| 260 | + case SemIR::Function::SpecialFunctionKind::Thunk: { |
| 261 | + // If we're about to form a direct call to a thunk, inline it. |
| 262 | + LoadImportRef(context, callee.thunk_decl_id()); |
262 | 263 |
|
263 |
| - // Name the thunk target within the enclosing scope of the thunk. |
264 |
| - auto thunk_ref_id = |
265 |
| - BuildNameRef(context, loc_id, callee.name_id, callee.thunk_decl_id(), |
266 |
| - callee_function.enclosing_specific_id); |
| 264 | + // Name the thunk target within the enclosing scope of the thunk. |
| 265 | + auto thunk_ref_id = |
| 266 | + BuildNameRef(context, loc_id, callee.name_id, callee.thunk_decl_id(), |
| 267 | + callee_function.enclosing_specific_id); |
267 | 268 |
|
268 |
| - // This recurses back into `PerformCall`. However, we never form a thunk to |
269 |
| - // a thunk, so we only recurse once. |
270 |
| - return PerformThunkCall(context, loc_id, callee_function.function_id, |
271 |
| - context.inst_blocks().Get(converted_args_id), |
272 |
| - thunk_ref_id); |
273 |
| - } |
| 269 | + // This recurses back into `PerformCall`. However, we never form a thunk |
| 270 | + // to a thunk, so we only recurse once. |
| 271 | + return PerformThunkCall(context, loc_id, callee_function.function_id, |
| 272 | + context.inst_blocks().Get(converted_args_id), |
| 273 | + thunk_ref_id); |
| 274 | + } |
| 275 | + |
| 276 | + case SemIR::Function::SpecialFunctionKind::HasCppThunk: { |
| 277 | + // This recurses back into `PerformCall`. However, we never form a C++ |
| 278 | + // thunk to a C++ thunk, so we only recurse once. |
| 279 | + return PerformCppThunkCall(context, loc_id, callee_function.function_id, |
| 280 | + context.inst_blocks().Get(converted_args_id), |
| 281 | + callee.cpp_thunk_decl_id()); |
| 282 | + } |
274 | 283 |
|
275 |
| - return GetOrAddInst<SemIR::Call>(context, loc_id, |
276 |
| - {.type_id = return_info.type_id, |
277 |
| - .callee_id = callee_id, |
278 |
| - .args_id = converted_args_id}); |
| 284 | + case SemIR::Function::SpecialFunctionKind::None: |
| 285 | + case SemIR::Function::SpecialFunctionKind::Builtin: { |
| 286 | + return GetOrAddInst<SemIR::Call>(context, loc_id, |
| 287 | + {.type_id = return_info.type_id, |
| 288 | + .callee_id = callee_id, |
| 289 | + .args_id = converted_args_id}); |
| 290 | + } |
| 291 | + } |
279 | 292 | }
|
280 | 293 |
|
281 | 294 | auto PerformCall(Context& context, SemIR::LocId loc_id, SemIR::InstId callee_id,
|
|
0 commit comments