From 84ca56c71fe14fe91d3c5b815d2119114ea6221f Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Tue, 20 Apr 2021 17:03:36 -0400 Subject: [PATCH] [wasm] Allocate a variable for all ref typed vregs and mark them as volatile. This forces the llvm backend to allocate a stack location for them, so they get GC tracking. --- src/mono/mono/mini/ir-emit.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mono/mono/mini/ir-emit.h b/src/mono/mono/mini/ir-emit.h index 0fd3accb019074..11f5d943b1bfcf 100644 --- a/src/mono/mono/mini/ir-emit.h +++ b/src/mono/mono/mini/ir-emit.h @@ -60,6 +60,14 @@ alloc_ireg_ref (MonoCompile *cfg) if (cfg->compute_gc_maps) mono_mark_vreg_as_ref (cfg, vreg); +#ifdef TARGET_WASM + /* + * For GC stack scanning to work, have to spill all reference variables to the stack. + */ + MonoInst *ins = mono_compile_create_var_for_vreg (cfg, m_class_get_byval_arg (mono_get_object_class ()), OP_LOCAL, vreg); + ins->flags |= MONO_INST_VOLATILE; +#endif + return vreg; }