On January 3, 2018 9:42:01 PM GMT+01:00, Jakub Jelinek <ja...@redhat.com> wrote: >Hi! > >When var-tracking pass isn't done (e.g. with -O2 -g -fno-var-tracking >or -O2 -gstatement-frontiers), rest_of_handle_final calls >variable_tracking_main in order to perform delete_vta_debug_insns >- replace the debug marker insns with notes. The problem with that is >that final pass is after freeing cfg, so using >FOR_EACH_BB/FOR_BB_INSNS_SAFE >is incorrect as the attached patch shows, e.g. the barriers pass swaps >a >barrier with the statement notes and nothing updates the bb boundaries. > >Fixed by doing the replacements on the raw insn stream when called from >final.c. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for >trunk?
OK. Richard. >2018-01-03 Jakub Jelinek <ja...@redhat.com> > > PR debug/83645 > * var-tracking.c (delete_vta_debug_insn): New inline function. > (delete_vta_debug_insns): Add USE_CFG argument, if true, walk just > insns from get_insns () to NULL instead of each bb separately. > Use delete_vta_debug_insn. No longer static. > (vt_debug_insns_local, variable_tracking_main_1): Adjust > delete_vta_debug_insns callers. > * rtl.h (delete_vta_debug_insns): Declare. > * final.c (rest_of_handle_final): Call delete_vta_debug_insns > instead of variable_tracking_main. > > * gcc.dg/pr83645.c: New test. > >--- gcc/var-tracking.c.jj 2018-01-03 10:19:54.385533834 +0100 >+++ gcc/var-tracking.c 2018-01-03 16:01:48.608217538 +0100 >@@ -10271,11 +10271,40 @@ vt_initialize (void) > > static int debug_label_num = 1; > >+/* Remove from the insn stream a single debug insn used for >+ variable tracking at assignments. */ >+ >+static inline void >+delete_vta_debug_insn (rtx_insn *insn) >+{ >+ if (DEBUG_MARKER_INSN_P (insn)) >+ { >+ reemit_marker_as_note (insn); >+ return; >+ } >+ >+ tree decl = INSN_VAR_LOCATION_DECL (insn); >+ if (TREE_CODE (decl) == LABEL_DECL >+ && DECL_NAME (decl) >+ && !DECL_RTL_SET_P (decl)) >+ { >+ PUT_CODE (insn, NOTE); >+ NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL; >+ NOTE_DELETED_LABEL_NAME (insn) >+ = IDENTIFIER_POINTER (DECL_NAME (decl)); >+ SET_DECL_RTL (decl, insn); >+ CODE_LABEL_NUMBER (insn) = debug_label_num++; >+ } >+ else >+ delete_insn (insn); >+} >+ > /* Remove from the insn stream all debug insns used for variable >- tracking at assignments. */ >+ tracking at assignments. USE_CFG should be false if the cfg is no >+ longer usable. */ > >-static void >-delete_vta_debug_insns (void) >+void >+delete_vta_debug_insns (bool use_cfg) > { > basic_block bb; > rtx_insn *insn, *next; >@@ -10283,33 +10312,20 @@ delete_vta_debug_insns (void) > if (!MAY_HAVE_DEBUG_INSNS) > return; > >- FOR_EACH_BB_FN (bb, cfun) >- { >- FOR_BB_INSNS_SAFE (bb, insn, next) >+ if (use_cfg) >+ FOR_EACH_BB_FN (bb, cfun) >+ { >+ FOR_BB_INSNS_SAFE (bb, insn, next) >+ if (DEBUG_INSN_P (insn)) >+ delete_vta_debug_insn (insn); >+ } >+ else >+ for (insn = get_insns (); insn; insn = next) >+ { >+ next = NEXT_INSN (insn); > if (DEBUG_INSN_P (insn)) >- { >- if (DEBUG_MARKER_INSN_P (insn)) >- { >- reemit_marker_as_note (insn); >- continue; >- } >- >- tree decl = INSN_VAR_LOCATION_DECL (insn); >- if (TREE_CODE (decl) == LABEL_DECL >- && DECL_NAME (decl) >- && !DECL_RTL_SET_P (decl)) >- { >- PUT_CODE (insn, NOTE); >- NOTE_KIND (insn) = NOTE_INSN_DELETED_DEBUG_LABEL; >- NOTE_DELETED_LABEL_NAME (insn) >- = IDENTIFIER_POINTER (DECL_NAME (decl)); >- SET_DECL_RTL (decl, insn); >- CODE_LABEL_NUMBER (insn) = debug_label_num++; >- } >- else >- delete_insn (insn); >- } >- } >+ delete_vta_debug_insn (insn); >+ } > } > > /* Run a fast, BB-local only version of var tracking, to take care of >@@ -10322,7 +10338,7 @@ static void > vt_debug_insns_local (bool skipped ATTRIBUTE_UNUSED) > { > /* ??? Just skip it all for now. */ >- delete_vta_debug_insns (); >+ delete_vta_debug_insns (true); > } > > /* Free the data structures needed for variable tracking. */ >@@ -10395,7 +10411,7 @@ variable_tracking_main_1 (void) > any pseudos at this point. */ > || targetm.no_register_allocation) > { >- delete_vta_debug_insns (); >+ delete_vta_debug_insns (true); > return 0; > } > >@@ -10423,7 +10439,7 @@ variable_tracking_main_1 (void) > { > vt_finalize (); > >- delete_vta_debug_insns (); >+ delete_vta_debug_insns (true); > > /* This is later restored by our caller. */ > flag_var_tracking_assignments = 0; >--- gcc/rtl.h.jj 2018-01-03 10:19:55.184533962 +0100 >+++ gcc/rtl.h 2018-01-03 15:56:13.089080504 +0100 >@@ -4254,6 +4254,7 @@ extern GTY(()) rtx stack_limit_rtx; > > /* In var-tracking.c */ > extern unsigned int variable_tracking_main (void); >+extern void delete_vta_debug_insns (bool); > > /* In stor-layout.c. */ > extern void get_mode_bounds (scalar_int_mode, int, >--- gcc/final.c.jj 2018-01-03 10:19:54.049533777 +0100 >+++ gcc/final.c 2018-01-03 15:56:48.509091487 +0100 >@@ -4544,7 +4544,7 @@ rest_of_handle_final (void) > /* Turn debug markers into notes if the var-tracking pass has not > been invoked. */ > if (!flag_var_tracking && MAY_HAVE_DEBUG_MARKER_INSNS) >- variable_tracking_main (); >+ delete_vta_debug_insns (false); > > assemble_start_function (current_function_decl, fnname); > final_start_function (get_insns (), asm_out_file, optimize); >--- gcc/testsuite/gcc.dg/pr83645.c.jj 2018-01-03 15:57:37.669106731 >+0100 >+++ gcc/testsuite/gcc.dg/pr83645.c 2018-01-03 15:57:06.575097090 +0100 >@@ -0,0 +1,14 @@ >+/* PR debug/83645 */ >+/* { dg-do compile } */ >+/* { dg-options "-O2 -g -fno-var-tracking" } */ >+ >+int a, b, c[1]; >+ >+void >+foo (void) >+{ >+ int i = 0; >+ b = a; >+ for (;;) >+ c[i++] = 7; >+} > > Jakub