On Thu, Jul 23, 2015 at 03:01:25PM -0700, Cesar Philippidis wrote: > On 07/23/2015 08:32 AM, Jakub Jelinek wrote: > > On Thu, Jul 23, 2015 at 08:20:50AM -0700, Cesar Philippidis wrote: > >> The attached patch does just that; it teaches > >> replace_block_vars_by_duplicates to replace the decls inside the > >> value-exprs with a duplicate too. It's kind of messy though. At the > >> moment I'm only considering VAR_DECL, PARM_DECL, RESULT_DECL, ADDR_EXPR, > >> ARRAY_REF, COMPONENT_REF, CONVERT_EXPR, NOP_EXPR, INDIRECT_REF and > >> MEM_REFs. I suspect that I may be missing some, but these are the only > >> ones that were triggered gcc_unreachable during testing. > > > > Ugh, that looks ugly, why do we have all the tree walkers? > > I'd unshare_expr the value expr first, you really don't want to share > > it anyway, and then just walk_tree and find all the decls in there > > (with *walk_subtrees on types and perhaps something else too) and for them > > replace_by_duplicate_decl (tp, vars_map, to_context); > > Something like the attached patch? Why do TREE_TYPEs need special handling?
They can have decls in various places like TYPE_SIZE_UNIT, TYPE_SIZE, the bounds of TYPE_DOMAIN etc. and I believe you generally don't want to replace those. Plus you risk infinite recursion then (unless walk_tree_without_duplicates). Most walk_tree callbacks just do something like if (IS_TYPE_OR_DECL_P (*tp)) *walk_subtrees = 0; Jakub