[patch] Avoid an unwanted decl re-map in copy_gimple_seq_and_replace_locals

Jakub Jelinek jakub@redhat.com
Mon Jan 11 16:38:00 GMT 2016


On Mon, Jan 11, 2016 at 09:41:31AM +0100, Richard Biener wrote:
> Hum.  Can't you check id->remapping_type_depth?  That said, how do
> we end up recursing into remap_decl when copying the variable length
> decl/type?  Can't we avoid the recursion (basically avoid remapping
> variable-size types at all?)

I guess it depends, VLA types that refer in their various gimplified
expressions only to decls defined outside of bind stmts we are duplicating
are fine as is, they don't need remapping, or could be remapped to VLA types
that use all the same temporary decls.
VLAs that have some or all references to decls inside of the bind stmts
we are duplicating IMHO need to be remapped.
So, perhaps we need to remap_decls in replace_locals_stmt in two phases
in presence of VLAs (or also vars with DECL_VALUE_EXPR)
- phase 1 would just walk the
  for (old_var = decls; old_var; old_var = DECL_CHAIN (old_var))
    {
      if (!can_be_nonlocal (old_var, id)
	  && ! variably_modified_type_p (TREE_TYPE (old_var), id->src_fn))
	remap_decl (old_var, id);
    }
- phase 2 - do the full remap_decls, but during that arrange that
  remap_decl for non-zero id->remapping_type_depth if (!n) just returns
  decl
That way, I think if the types refer to some temporaries that are defined
in the bind stmts being copied, they will be properly duplicated, otherwise
they will be shared.
So, we'd need some flag in *id (just bool bitfield would be enough) that would
allow replace_locals_stmt to set it before the remap_decls call in phase 2
and clear it afterwards, and use that flag together with
id->remapping_type_depth in remap_decls.

	Jakub



More information about the Gcc-patches mailing list