This is the mail archive of the gcc-patches@gcc.gnu.org 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]

[vta,vta4.3] don't let debug stmts change line info


Another difference detected with -fcompare-debug was that the
expansion of debug stmts that contained expressions with location
information might cause insns emitted right after them, out of stmts
without location info, to get different location info.

This patch arranges for location information to be preserved across
the expansion of debug stmts, so that non-debug insns get the same
location information regardless of debug insns.

Patches follow for vta and vta4.3, respectively.

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* cfgexpand.c (expand_gimple_basic_block): Remove duplicate stmt
	declaration.  Preserve source location around expanding debug
	stmts.
	* cfglayout.c (get_curr_insn_source_location): New fn.
	(get_curr_insn_block): New fn.
	* rtl.h (get_curr_insn_source_location): Declare.
	(get_curr_insn_block): Declare.

Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c.orig	2008-09-05 03:09:52.000000000 -0300
+++ gcc/cfgexpand.c	2008-09-05 03:11:33.000000000 -0300
@@ -2623,9 +2623,10 @@ expand_gimple_basic_block (basic_block b
 
   for (; !gsi_end_p (gsi); gsi_next (&gsi))
     {
-      gimple stmt = gsi_stmt (gsi);
       basic_block new_bb;
 
+      stmt = gsi_stmt (gsi);
+
       /* Expand this statement, then evaluate the resulting RTL and
 	 fixup the CFG accordingly.  */
       if (gimple_code (stmt) == GIMPLE_COND)
@@ -2636,44 +2637,65 @@ expand_gimple_basic_block (basic_block b
 	}
       else if (IS_DEBUG_STMT (stmt))
 	{
-	  tree var = VAR_DEBUG_VALUE_VAR (stmt);
-	  tree value = VAR_DEBUG_VALUE_VALUE (stmt);
-	  rtx val;
-	  enum machine_mode mode;
+	  location_t sloc = get_curr_insn_source_location ();
+	  tree sblock = get_curr_insn_block ();
+	  gimple_stmt_iterator nsi = gsi;
 
-	  last = get_last_insn ();
+	  for (;;)
+	    {
+	      tree var = VAR_DEBUG_VALUE_VAR (stmt);
+	      tree value = VAR_DEBUG_VALUE_VALUE (stmt);
+	      rtx val;
+	      enum machine_mode mode;
 
-	  if (value == VAR_DEBUG_VALUE_NOVALUE)
-	    val = NULL_RTX;
-	  else
-	    val = expand_debug_expr (value);
+	      last = get_last_insn ();
 
-	  if (DECL_P (var))
-	    mode = DECL_MODE (var);
-	  else
-	    mode = TYPE_MODE (TREE_TYPE (var));
+	      if (value == VAR_DEBUG_VALUE_NOVALUE)
+		val = NULL_RTX;
+	      else
+		val = expand_debug_expr (value);
+
+	      set_curr_insn_source_location (gimple_location (stmt));
+	      set_curr_insn_block (gimple_block (stmt));
+
+	      if (DECL_P (var))
+		mode = DECL_MODE (var);
+	      else
+		mode = TYPE_MODE (TREE_TYPE (var));
+
+	      if (!val)
+		val = gen_rtx_UNKNOWN_VAR_LOC ();
+	      else
+		gcc_assert (mode == GET_MODE (val)
+			    || GET_CODE (val) == CONST_INT
+			    || GET_CODE (val) == CONST_FIXED
+			    || GET_CODE (val) == CONST_DOUBLE);
 
-	  if (!val)
-	    val = gen_rtx_UNKNOWN_VAR_LOC ();
-	  else
-	    gcc_assert (mode == GET_MODE (val)
-			|| GET_CODE (val) == CONST_INT
-			|| GET_CODE (val) == CONST_FIXED
-			|| GET_CODE (val) == CONST_DOUBLE);
+	      val = gen_rtx_VAR_LOCATION
+		(mode, var, val, VAR_INIT_STATUS_INITIALIZED);
 
-	  val = gen_rtx_VAR_LOCATION
-	    (mode, var, val, VAR_INIT_STATUS_INITIALIZED);
+	      val = emit_debug_insn (val);
 
-	  val = emit_debug_insn (val);
+	      maybe_dump_rtl_for_gimple_stmt (stmt, last);
 
-	  maybe_dump_rtl_for_gimple_stmt (stmt, last);
+	      if (last != PREV_INSN (val))
+		{
+		  debug_gimple_stmt (stmt);
+		  debug_rtx_range (NEXT_INSN (last), get_last_insn ());
+		  gcc_unreachable ();
+		}
 
-	  if (last != PREV_INSN (val))
-	    {
-	      debug_gimple_stmt (stmt);
-	      debug_rtx_range (NEXT_INSN (last), get_last_insn ());
-	      gcc_unreachable ();
+	      gsi = nsi;
+	      gsi_next (&nsi);
+	      if (gsi_end_p (nsi))
+		break;
+	      stmt = gsi_stmt (nsi);
+	      if (!IS_DEBUG_STMT (stmt))
+		break;
 	    }
+
+	  set_curr_insn_source_location (sloc);
+	  set_curr_insn_block (sblock);
 	}
       else
 	{
Index: gcc/cfglayout.c
===================================================================
--- gcc/cfglayout.c.orig	2008-09-05 03:09:51.000000000 -0300
+++ gcc/cfglayout.c	2008-09-05 03:09:53.000000000 -0300
@@ -282,7 +282,14 @@ set_curr_insn_source_location (location_
   curr_location = location;
 }
 
-/* Set current scope block. */
+/* Get current location.  */
+location_t
+get_curr_insn_source_location (void)
+{
+  return curr_location;
+}
+
+/* Set current scope block.  */
 void
 set_curr_insn_block (tree b)
 {
@@ -294,6 +301,13 @@ set_curr_insn_block (tree b)
     curr_block = b;
 }
 
+/* Get current scope block.  */
+tree
+get_curr_insn_block (void)
+{
+  return curr_block;
+}
+
 /* Return current insn locator.  */
 int
 curr_insn_locator (void)
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h.orig	2008-09-05 03:09:39.000000000 -0300
+++ gcc/rtl.h	2008-09-05 03:09:53.000000000 -0300
@@ -2367,7 +2367,9 @@ extern const struct rtl_hooks general_rt
 extern void insn_locators_alloc (void);
 extern void insn_locators_finalize (void);
 extern void set_curr_insn_source_location (location_t);
+extern location_t get_curr_insn_source_location (void);
 extern void set_curr_insn_block (tree);
+extern tree get_curr_insn_block (void);
 extern int curr_insn_locator (void);
 
 #endif /* ! GCC_RTL_H */
for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* cfgexpand.c (expand_gimple_basic_block): Remove duplicate stmt
	declaration.  Preserve source location around expanding debug
	stmts.
	* cfglayout.c (get_curr_insn_source_location): New fn.
	(get_curr_insn_block): New fn.
	* rtl.h (get_curr_insn_source_location): Declare.
	(get_curr_insn_block): Declare.

Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c.orig	2008-09-05 03:18:46.000000000 -0300
+++ gcc/cfgexpand.c	2008-09-05 03:50:28.000000000 -0300
@@ -2312,9 +2312,10 @@ expand_gimple_basic_block (basic_block b
 
   for (; !tsi_end_p (tsi); tsi_next (&tsi))
     {
-      tree stmt = tsi_stmt (tsi);
       basic_block new_bb;
 
+      stmt = tsi_stmt (tsi);
+
       if (!stmt)
 	continue;
 
@@ -2328,44 +2329,66 @@ expand_gimple_basic_block (basic_block b
 	}
       else if (TREE_CODE (stmt) == VAR_DEBUG_VALUE)
 	{
-	  tree var = VAR_DEBUG_VALUE_VAR (stmt);
-	  tree value = VAR_DEBUG_VALUE_VALUE (stmt);
-	  rtx val;
-	  enum machine_mode mode;
+	  location_t sloc = get_curr_insn_source_location ();
+	  tree sblock = get_curr_insn_block ();
+	  tree_stmt_iterator nsi = tsi;
 
-	  last = get_last_insn ();
+	  for (;;)
+	    {
+	      tree var = VAR_DEBUG_VALUE_VAR (stmt);
+	      tree value = VAR_DEBUG_VALUE_VALUE (stmt);
+	      rtx val;
+	      enum machine_mode mode;
 
-	  if (value == VAR_DEBUG_VALUE_NOVALUE)
-	    val = NULL_RTX;
-	  else
-	    val = expand_debug_expr (value);
+	      last = get_last_insn ();
 
-	  if (DECL_P (var))
-	    mode = DECL_MODE (var);
-	  else
-	    mode = TYPE_MODE (TREE_TYPE (var));
+	      if (value == VAR_DEBUG_VALUE_NOVALUE)
+		val = NULL_RTX;
+	      else
+		val = expand_debug_expr (value);
+
+	      set_curr_insn_source_location (location_from_locus
+					     (GIMPLE_STMT_LOCUS (stmt)));
+	      set_curr_insn_block (GIMPLE_STMT_BLOCK (stmt));
+
+	      if (DECL_P (var))
+		mode = DECL_MODE (var);
+	      else
+		mode = TYPE_MODE (TREE_TYPE (var));
+
+	      if (!val)
+		val = gen_rtx_UNKNOWN_VAR_LOC ();
+	      else
+		gcc_assert (mode == GET_MODE (val)
+			    || GET_CODE (val) == CONST_INT
+			    || GET_CODE (val) == CONST_FIXED
+			    || GET_CODE (val) == CONST_DOUBLE);
 
-	  if (!val)
-	    val = gen_rtx_UNKNOWN_VAR_LOC ();
-	  else
-	    gcc_assert (mode == GET_MODE (val)
-			|| GET_CODE (val) == CONST_INT
-			|| GET_CODE (val) == CONST_FIXED
-			|| GET_CODE (val) == CONST_DOUBLE);
+	      val = gen_rtx_VAR_LOCATION
+		(mode, var, val, VAR_INIT_STATUS_INITIALIZED);
 
-	  val = gen_rtx_VAR_LOCATION
-	    (mode, var, val, VAR_INIT_STATUS_INITIALIZED);
+	      val = emit_debug_insn (val);
 
-	  val = emit_debug_insn (val);
+	      maybe_dump_rtl_for_tree_stmt (stmt, last);
 
-	  maybe_dump_rtl_for_tree_stmt (stmt, last);
+	      if (last != PREV_INSN (val))
+		{
+		  debug_generic_expr (stmt);
+		  debug_rtx_range (NEXT_INSN (last), get_last_insn ());
+		  gcc_unreachable ();
+		}
 
-	  if (last != PREV_INSN (val))
-	    {
-	      debug_generic_expr (stmt);
-	      debug_rtx_range (NEXT_INSN (last), get_last_insn ());
-	      gcc_unreachable ();
+	      tsi = nsi;
+	      tsi_next (&nsi);
+	      if (tsi_end_p (nsi))
+		break;
+	      stmt = tsi_stmt (nsi);
+	      if (!IS_DEBUG_STMT (stmt))
+		break;
 	    }
+
+	  set_curr_insn_source_location (sloc);
+	  set_curr_insn_block (sblock);
 	}
       else
 	{
Index: gcc/cfglayout.c
===================================================================
--- gcc/cfglayout.c.orig	2008-09-05 03:16:04.000000000 -0300
+++ gcc/cfglayout.c	2008-09-05 03:20:09.000000000 -0300
@@ -287,7 +287,14 @@ set_curr_insn_source_location (location_
   curr_location = location;
 }
 
-/* Set current scope block. */
+/* Get current location.  */
+location_t
+get_curr_insn_source_location (void)
+{
+  return curr_location;
+}
+
+/* Set current scope block.  */
 void
 set_curr_insn_block (tree b)
 {
@@ -299,6 +306,13 @@ set_curr_insn_block (tree b)
     curr_block = b;
 }
 
+/* Get current scope block.  */
+tree
+get_curr_insn_block (void)
+{
+  return curr_block;
+}
+
 /* Return current insn locator.  */
 int
 curr_insn_locator (void)
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h.orig	2008-08-12 03:45:28.000000000 -0300
+++ gcc/rtl.h	2008-09-05 03:20:09.000000000 -0300
@@ -2364,7 +2364,9 @@ extern const struct rtl_hooks general_rt
 extern void insn_locators_alloc (void);
 extern void insn_locators_finalize (void);
 extern void set_curr_insn_source_location (location_t);
+extern location_t get_curr_insn_source_location (void);
 extern void set_curr_insn_block (tree);
+extern tree get_curr_insn_block (void);
 extern int curr_insn_locator (void);
 
 #endif /* ! GCC_RTL_H */
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member       ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}

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