Mangle the signature decl when mangling a thunk. (#7177)

Fixes mangling collisions when two thunks with the same name (eg, `Op`)
are created in the same context, which in turn would lead to LLVM
verifier failures and miscompiles.

To support this, add a new value store to track a little more
information about thunks beyond what's in the `Function`.
This commit is contained in:
Richard Smith
2026-05-07 21:58:29 +00:00
committed by GitHub
parent 031ec0a140
commit bc06f6c5ec
40 changed files with 637 additions and 341 deletions
+4 -2
View File
@@ -263,11 +263,13 @@ auto PerformCallToFunction(Context& context, SemIR::LocId loc_id,
switch (callee.special_function_kind) {
case SemIR::Function::SpecialFunctionKind::Thunk: {
// If we're about to form a direct call to a thunk, inline it.
LoadImportRef(context, callee.thunk_decl_id());
auto callee_inst_id =
context.sem_ir().thunks().Get(callee.thunk_id()).callee_id;
LoadImportRef(context, callee_inst_id);
// Name the thunk target within the enclosing scope of the thunk.
auto thunk_ref_id =
BuildNameRef(context, loc_id, callee.name_id, callee.thunk_decl_id(),
BuildNameRef(context, loc_id, callee.name_id, callee_inst_id,
callee_function.enclosing_specific_id);
auto param_pattern_ids =