Support const eval when calling a C++ thunk (#6947)

This makes it possible to do const eval when calling a constexpr C++
function with params and return types other than 32/64-bit integers.

Most of the new logic is in `MaybeModifyCppThunkCallForConstEval`, which
is called by `MakeConstantForCall`. This checks if the callee is a C++
thunk (using a new `SpecialFunctionKind::CppThunk` variant), and if so
it:
* Changes the callee from the C++ thunk to the thunk's callee
* Remaps parameters that are passed by pointer to the thunk to the
underlying value
* Drops the return value parameter, if present
This commit is contained in:
Nicholas Bishop
2026-04-01 21:34:41 +00:00
committed by GitHub
parent 5b7c908e8b
commit 0075d530b9
11 changed files with 147 additions and 4 deletions
+3 -1
View File
@@ -1587,8 +1587,10 @@ static auto ImportFunctionDecl(Context& context, SemIR::LocId loc_id,
context, loc_id, import_ir_inst_id, thunk_clang_decl,
{.num_params =
static_cast<int32_t>(thunk_clang_decl->getNumParams())})) {
auto& thunk_function = context.functions().Get(*thunk_function_id);
thunk_function.SetCppThunk(function_info.first_owning_decl_id);
SemIR::InstId thunk_function_decl_id =
context.functions().Get(*thunk_function_id).first_owning_decl_id;
thunk_function.first_owning_decl_id;
function_info.SetHasCppThunk(thunk_function_decl_id);
}
}