From ce6bf91a8384362dcde19a6691de291743dd97c4 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Thu, 2 Oct 2025 21:11:31 +0200 Subject: [PATCH] Avoid extra work when `thunk_required` is already true in `IsCppThunkRequired()` (#6150) Also set `thunk_required` in a more consistent way, to avoid bugs like the one fixed in #6152. Part #6148. --- toolchain/check/cpp/thunk.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/toolchain/check/cpp/thunk.cpp b/toolchain/check/cpp/thunk.cpp index 94cf9228b58f..0cf43981dc58 100644 --- a/toolchain/check/cpp/thunk.cpp +++ b/toolchain/check/cpp/thunk.cpp @@ -110,6 +110,7 @@ auto IsCppThunkRequired(Context& context, const SemIR::Function& function) for (auto* param : decl->parameters()) { if (param->getType()->isReferenceType()) { thunk_required = true; + break; } } } @@ -129,12 +130,10 @@ auto IsCppThunkRequired(Context& context, const SemIR::Function& function) if (param_id == SemIR::ErrorInst::InstId) { return false; } - if (!thunk_required && + thunk_required = + thunk_required || IsThunkRequiredForType( - context, - context.insts().GetAs(param_id).type_id)) { - thunk_required = true; - } + context, context.insts().GetAs(param_id).type_id); } return thunk_required;