From 61600a33b840720c0eb21e380cdcec049713aba8 Mon Sep 17 00:00:00 2001 From: Jonathan Worthington Date: Fri, 15 Oct 2021 16:21:18 +0200 Subject: [PATCH] Don't duplicately set up fake temps We allow resume init values from one resumption to be used in the next one. This works out because while we only keep info around about the resumption we are currently handling, the resume init arg will have been loaded into a temporary at the right time, and then the dispatch program can later reference that temporary. When we are producing a dispatch program recording, we didn't really run the resulting dispatch program, so fake up the temporaries. We erroneously did this for every mention of the resume init arg, however, meaning we could overwrite the correct value already stored with a bogus one later. Fix it by making sure we only ever accept the first value for a given fake temporary. --- src/disp/program.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/disp/program.c b/src/disp/program.c index ea26be4f85..95a6bc92f4 100644 --- a/src/disp/program.c +++ b/src/disp/program.c @@ -2346,6 +2346,16 @@ static void emit_args_ops(MVMThreadContext *tc, MVMCallStackDispatchRecord *reco static void add_resume_init_temp_to_fake(MVMThreadContext *tc, compile_state *cs, MVMDispProgramRecordingResumption *rec_res, MVMuint32 temp_idx, MVMuint32 init_arg_idx) { + /* Make sure we didn't already add the argument to fake; it's possible we + * will end up overwriting it with the wrong value (because it could have + * previously been set from a resumption other than the one we are now + * in). */ + MVMuint32 i; + for (i = 0; i < MVM_VECTOR_ELEMS(cs->fake_temps); i++) + if (cs->fake_temps[i].temp_idx == temp_idx) + return; + + /* Not found, so add it. */ MVMRegister value; MVMCallsiteFlags unused; MVM_capture_arg_by_flag_index(tc, rec_res->initial_resume_capture.capture, init_arg_idx,