https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119370
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Guess the bug is in emit_partial_init_fini_fn
/* We will emit 'init' twice, and it is modified in-place during
gimplification. Make a copy here. */
if (omp_target)
{
/* We've already emitted INIT in the host version of the ctor/dtor
function. We need to deep-copy it (including new versions of
local variables introduced, etc.) for use in the target
ctor/dtor function. */
copy_body_data id;
hash_map<tree, tree> decl_map;
memset (&id, 0, sizeof (id));
id.src_fn = host_fn;
id.dst_fn = current_function_decl;
id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
id.decl_map = &decl_map;
id.copy_decl = copy_decl_no_change;
id.transform_call_graph_edges = CB_CGE_DUPLICATE;
id.transform_new_cfg = true;
id.transform_return_to_modify = false;
id.eh_lp_nr = 0;
walk_tree (&init, copy_tree_body_r, &id, NULL);
}
/* Do one initialization or destruction. */
one_static_initialization_or_destruction (initp, decl, init, omp_target);
But the temporaries have NULL DECL_CONTEXT before the gimplification and so the
code doesn't copy them and using the same automatic temporaries in 2 different
functions is invalid. Let me see if I can just set DECL_CONTEXT for those.
before this walk.