This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Small improvements to coverage info (1/n)


we have collected a number of small improvements to coverage info generated by 
the compiler over the years.  One of the issues is when a new expression or 
statement is built without source location information and ends up inheriting 
the source location information of the previous instruction in the debug info, 
which can be totally unrelated.

Tested on x86_64-suse-linux, both GCC and GDB, OK for mainline?

2019-07-03  Eric Botcazou  <>

	* tree-cfg.c (gimple_make_forwarder_block): Propagate location info on
	phi nodes if possible.
	* tree-scalar-evolution.c (final_value_replacement_loop): Propagate
	location info on the newly created statement.
	* tree-ssa-loop-manip.c (create_iv): Propagate location info on the
	newly created increment if needed.

Eric Botcazou
Index: tree-cfg.c
--- tree-cfg.c	(revision 272930)
+++ tree-cfg.c	(working copy)
@@ -5756,6 +5756,7 @@ gimple_make_forwarder_block (edge fallth
   basic_block dummy, bb;
   tree var;
   gphi_iterator gsi;
+  bool forward_location_p;
   dummy = fallthru->src;
   bb = fallthru->dest;
@@ -5763,6 +5764,9 @@ gimple_make_forwarder_block (edge fallth
   if (single_pred_p (bb))
+  /* We can forward location info if we have only one predecessor.  */
+  forward_location_p = single_pred_p (dummy);
   /* If we redirected a branch we must create new PHI nodes at the
      start of BB.  */
   for (gsi = gsi_start_phis (dummy); !gsi_end_p (gsi); gsi_next (&gsi))
@@ -5774,7 +5778,8 @@ gimple_make_forwarder_block (edge fallth
       new_phi = create_phi_node (var, bb);
       gimple_phi_set_result (phi, copy_ssa_name (var, phi));
       add_phi_arg (new_phi, gimple_phi_result (phi), fallthru,
+		   forward_location_p
+		   ? gimple_phi_arg_location (phi, 0) : UNKNOWN_LOCATION);
   /* Add the arguments we have stored on edges.  */
Index: tree-scalar-evolution.c
--- tree-scalar-evolution.c	(revision 272930)
+++ tree-scalar-evolution.c	(working copy)
@@ -3680,6 +3680,8 @@ final_value_replacement_loop (struct loo
 					true, GSI_SAME_STMT);
       gassign *ass = gimple_build_assign (rslt, def);
+      gimple_set_location (ass,
+			   gimple_phi_arg_location (phi, exit->dest_idx));
       gsi_insert_before (&gsi, ass, GSI_SAME_STMT);
       if (dump_file)
Index: tree-ssa-loop-manip.c
--- tree-ssa-loop-manip.c	(revision 272930)
+++ tree-ssa-loop-manip.c	(working copy)
@@ -126,10 +126,22 @@ create_iv (tree base, tree step, tree va
     gsi_insert_seq_on_edge_immediate (pe, stmts);
   stmt = gimple_build_assign (va, incr_op, vb, step);
+  /* Prevent the increment from inheriting a bogus location if it is not put
+     immediately after a statement whose location is known.  */
   if (after)
-    gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
+    {
+      if (gsi_end_p (*incr_pos))
+	{
+	  edge e = single_succ_edge (gsi_bb (*incr_pos));
+	  gimple_set_location (stmt, e->goto_locus);
+	}
+      gsi_insert_after (incr_pos, stmt, GSI_NEW_STMT);
+    }
-    gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
+    {
+      gimple_set_location (stmt, gimple_location (gsi_stmt (*incr_pos)));
+      gsi_insert_before (incr_pos, stmt, GSI_NEW_STMT);
+    }
   initial = force_gimple_operand (base, &stmts, true, var);
   if (stmts)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]