https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66714
--- Comment #14 from vries at gcc dot gnu.org ---
1.
In lower_omp_target for function fn3, we handle clause 'map(alloc:bD.1833
[pointer assign, bias: 0])' with variable-sized bD.1833.
The var bD.1833 has value-expr *b.0D.1844. For b.0D.1844, we search the
associated decl with lookup_decl, and find b.0D.1854. We set the value-expr for
b.0D.1854 to '*.omp_data_iD.1851->b.0D.1870'.
Associated code:
...
if (DECL_SIZE (var)
&& TREE_CODE (DECL_SIZE (var)) != INTEGER_CST)
{
tree var2 = DECL_VALUE_EXPR (var);
gcc_assert (TREE_CODE (var2) == INDIRECT_REF);
var2 = TREE_OPERAND (var2, 0);
gcc_assert (DECL_P (var2));
var = var2;
}
if (!maybe_lookup_field (var, ctx))
continue;
if (offloaded)
{
x = build_receiver_ref (var, true, ctx);
tree new_var = lookup_decl (var, ctx);
if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
&& !OMP_CLAUSE_MAP_ZERO_BIAS_ARRAY_SECTION (c)
&& TREE_CODE (TREE_TYPE (var)) == ARRAY_TYPE)
x = build_simple_mem_ref (x);
SET_DECL_VALUE_EXPR (new_var, x);
DECL_HAS_VALUE_EXPR_P (new_var) = 1;
}
...
2.
In replace_block_vars_by_duplicates, called from move_sese_region_to_fn, called
from expand_omp_target:
- we copy the value-expr *b.0D.1854 from bD.1855 to bD.1916, and
- we copy the value-expr *.omp_data_iD.1851->b.0D.1870 from b.0D.1854 to
b.0D.1917
Associated code:
...
t = *tp;
if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != CONST_DECL)
continue;
replace_by_duplicate_decl (&t, vars_map, to_context);
if (t != *tp)
{
if (TREE_CODE (*tp) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (*tp))
{
SET_DECL_VALUE_EXPR (t, DECL_VALUE_EXPR (*tp));
DECL_HAS_VALUE_EXPR_P (t) = 1;
}
DECL_CHAIN (t) = DECL_CHAIN (*tp);
*tp = t;
}
...
3.
In expand_omp_target for function fn3._omp_fn.0 we remove b.0D.1854 and bD.1855
from the local_decls, because the DECL_CONTEXT is fn3, rather than
fn3._omp_fn.0.
Associated code:
...
/* Remove non-local VAR_DECLs from child_cfun->local_decls list. */
num = vec_safe_length (child_cfun->local_decls);
for (srcidx = 0, dstidx = 0; srcidx < num; srcidx++)
{
t = (*child_cfun->local_decls)[srcidx];
if (DECL_CONTEXT (t) == cfun->decl)
continue;
if (srcidx != dstidx)
(*child_cfun->local_decls)[dstidx] = t;
dstidx++;
}
...
4.
Now that b.0D.1854 and bD.1855 are no longer declared in a function, they're no
longer live, and during garbage collection, we remove:
- cache entry (b.0D.1854, *.omp_data_iD.1851->b.0D.1870), and
- cache entry (bD.1855, *b.0D.1854)
from hash table value_expr_for_decl.
5.
During dwarf processing of fn3._omp_fn.0, we process a scope with decl bD.1916,
which has value-expr *b.0D.1854. When processing b.0D.1854 in
loc_list_from_tree, we run into the sigsegv because the value-expr for
b.0D.1854 is NULL (since the entry has been removed from the hash table).
Associated code:
...
/* FALLTHRU */
case PARM_DECL:
case RESULT_DECL:
if (DECL_HAS_VALUE_EXPR_P (loc))
return loc_list_from_tree (DECL_VALUE_EXPR (loc),
want_address, context);
...