On Thu, Mar 25, 2021 at 04:20:54PM -0400, Jason Merrill wrote: > > but it is also cp_walk_subtrees DECL_EXPR handling: > > case DECL_EXPR: > > /* User variables should be mentioned in BIND_EXPR_VARS > > and their initializers and sizes walked when walking > > the containing BIND_EXPR. Compiler temporaries are > > handled here. And also normal variables in templates, > > since do_poplevel doesn't build a BIND_EXPR then. */ > > if (VAR_P (TREE_OPERAND (*tp, 0)) > > && (processing_template_decl > > || (DECL_ARTIFICIAL (TREE_OPERAND (*tp, 0)) > > && !TREE_STATIC (TREE_OPERAND (*tp, 0))))) > > { > > What if we WALK_SUBTREE (DECL_EXPR_DECL (*tp)) here, instead of the > bot_replace hunk? OK either way.
The above hunk is cp_walk_subtrees, we shouldn't change that IMO. We could do it in bot_manip instead of bot_replace by doing roughly: if (TREE_CODE (*tp) == DECL_EXPR && VAR_P (DECL_EXPR_DECL (*tp)) && DECL_ARTIFICIAL (DECL_EXPR_DECL (*tp)) && !TREE_STATIC (DECL_EXPR_DECL (*tp))) { tree t; splay_tree_node n = splay_tree_lookup (target_remap, (splay_tree_key) DECL_EXPR_DECL (*tp)); if (n) t = (tree) n->value; else { t = create_temporary_var (TREE_TYPE (DECL_EXPR_DECL (*tp))); DECL_INITIAL (t) = DECL_INITIAL (DECL_EXPR_DECL (*tp)); splay_tree_insert (target_remap, (splay_tree_key) DECL_EXPR_DECL (*tp), (splay_tree_value) t); } copy_tree_r (tp, walk_subtrees, NULL); DECL_EXPR_DECL (*tp) = t; if (data.clear_location && EXPR_HAS_LOCATION (*tp)) SET_EXPR_LOCATION (*tp, input_location); return NULL_TREE; } plus the current BIND_EXPR handling afterwards. I.e. update DECL_EXPR_DECL of the DECL_EXPR right away in bot_manip rather than waiting until bot_replace with that. If you prefer that, I can test it tonight. Jakub