While bringing early LTO debug up-to-speed I noticed the following two issues. The first patch avoids useless work in note_variable_value_in_expr and actually makes use of the DIE we eventually create in resolve_variable_value_in_expr.
The second avoids generating a DW_OP_GNU_variable_value for a decl we'll never have a DIE for -- this might be less obvious than the other patch but I think we'll also never have any other debug info we can resolve the decl with(?) Bootstrapped and tested the first patch sofar on x86_64-unknown-linux-gnu, 2nd is pending. Ok? Thanks, Richard. 2017-05-15 Richard Biener <rguent...@suse.de> * dwarf2out.c (resolve_variable_value_in_expr): Lookup DIE just generated. (note_variable_value_in_expr): If we resolved the decl ref do not push to the stack. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 248055) +++ gcc/dwarf2out.c (working copy) @@ -30109,8 +30109,9 @@ resolve_variable_value_in_expr (dw_attr_ break; } /* Create DW_TAG_variable that we can refer to. */ - ref = gen_decl_die (decl, NULL_TREE, NULL, - lookup_decl_die (current_function_decl)); + gen_decl_die (decl, NULL_TREE, NULL, + lookup_decl_die (current_function_decl)); + ref = lookup_decl_die (decl); if (ref) { loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref; @@ -30203,6 +30204,7 @@ note_variable_value_in_expr (dw_die_ref loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref; loc->dw_loc_oprnd1.v.val_die_ref.die = ref; loc->dw_loc_oprnd1.v.val_die_ref.external = 0; + continue; } if (VAR_P (decl) && DECL_CONTEXT (decl) 2017-05-15 Richard Biener <rguent...@suse.de> * dwarf2out.c (loc_list_from_tree_1): Do not create DW_OP_GNU_variable_value for DECL_IGNORED_P decls. Index: gcc/dwarf2out.c =================================================================== --- gcc/dwarf2out.c (revision 248054) +++ gcc/dwarf2out.c (working copy) @@ -17373,6 +17685,7 @@ loc_list_from_tree_1 (tree loc, int want && early_dwarf && current_function_decl && want_address != 1 + && ! DECL_IGNORED_P (loc) && (INTEGRAL_TYPE_P (TREE_TYPE (loc)) || POINTER_TYPE_P (TREE_TYPE (loc))) && DECL_CONTEXT (loc) == current_function_decl