Hi,

This patch fixes debug info for expr and jump stmt.

Bootstrapped and passed gcc regression tests.

Is it okay for trunk?

Thanks,
Dehao

gcc/ChangeLog:
2012-10-25  Dehao Chen  <de...@google.com>

* tree-eh.c (do_return_redirection): Set location for jump statement.
(do_goto_redirection): Likewise.
(frob_into_branch_around): Likewise.
(lower_try_finally_nofallthru): Likewise.
(lower_try_finally_copy): Likewise.
(lower_try_finally_switch): Likewise.
* cfgexpand.c (set_expr_location_r): New callback function.
(gimple_assign_rhs_to_tree): Walk the expr recursively.
(expand_call_stmt): Likewise.
(expand_gimple_stmt_1): Likewise.
Index: gcc/tree-eh.c
===================================================================
--- gcc/tree-eh.c       (revision 192809)
+++ gcc/tree-eh.c       (working copy)
@@ -739,6 +739,7 @@ do_return_redirection (struct goto_queue_node *q,
     gimple_seq_add_seq (&q->repl_stmt, mod);
 
   x = gimple_build_goto (finlab);
+  gimple_set_location (x, q->location);
   gimple_seq_add_stmt (&q->repl_stmt, x);
 }
 
@@ -758,6 +759,7 @@ do_goto_redirection (struct goto_queue_node *q, tr
     gimple_seq_add_seq (&q->repl_stmt, mod);
 
   x = gimple_build_goto (finlab);
+  gimple_set_location (x, q->location);
   gimple_seq_add_stmt (&q->repl_stmt, x);
 }
 
@@ -857,6 +859,7 @@ frob_into_branch_around (gimple tp, eh_region regi
       if (!over)
        over = create_artificial_label (loc);
       x = gimple_build_goto (over);
+      gimple_set_location (x, loc);
       gimple_seq_add_stmt (&cleanup, x);
     }
   gimple_seq_add_seq (&eh_seq, cleanup);
@@ -1085,6 +1088,7 @@ lower_try_finally_nofallthru (struct leh_state *st
          emit_post_landing_pad (&eh_seq, tf->region);
 
          x = gimple_build_goto (lab);
+         gimple_set_location (x, gimple_location (tf->try_finally_expr));
          gimple_seq_add_stmt (&eh_seq, x);
        }
     }
@@ -1223,6 +1227,7 @@ lower_try_finally_copy (struct leh_state *state, s
 
       tmp = lower_try_finally_fallthru_label (tf);
       x = gimple_build_goto (tmp);
+      gimple_set_location (x, tf_loc);
       gimple_seq_add_stmt (&new_stmt, x);
     }
 
@@ -1395,6 +1400,7 @@ lower_try_finally_switch (struct leh_state *state,
 
       tmp = lower_try_finally_fallthru_label (tf);
       x = gimple_build_goto (tmp);
+      gimple_set_location (x, tf_loc);
       gimple_seq_add_stmt (&switch_body, x);
     }
 
@@ -1423,6 +1429,7 @@ lower_try_finally_switch (struct leh_state *state,
       gimple_seq_add_stmt (&eh_seq, x);
 
       x = gimple_build_goto (finally_label);
+      gimple_set_location (x, tf_loc);
       gimple_seq_add_stmt (&eh_seq, x);
 
       tmp = build_int_cst (integer_type_node, eh_index);
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c     (revision 192809)
+++ gcc/cfgexpand.c     (working copy)
@@ -58,6 +58,17 @@ gimple currently_expanding_gimple_stmt;
 
 static rtx expand_debug_expr (tree);
 
+/* Call back function to set the expr location as gimple location.  */
+
+static tree
+set_expr_location_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, void *data)
+{
+  gimple stmt = (gimple) data;
+  if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (*tp))
+    SET_EXPR_LOCATION (*tp, gimple_location (stmt));
+  return NULL_TREE;
+}
+
 /* Return an expression tree corresponding to the RHS of GIMPLE
    statement STMT.  */
 
@@ -98,8 +109,7 @@ gimple_assign_rhs_to_tree (gimple stmt)
   else
     gcc_unreachable ();
 
-  if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (t))
-    SET_EXPR_LOCATION (t, gimple_location (stmt));
+  walk_tree (&t, set_expr_location_r, stmt, NULL);
 
   return t;
 }
@@ -1990,7 +2000,7 @@ expand_call_stmt (gimple stmt)
   else
     CALL_FROM_THUNK_P (exp) = gimple_call_from_thunk_p (stmt);
   CALL_EXPR_VA_ARG_PACK (exp) = gimple_call_va_arg_pack_p (stmt);
-  SET_EXPR_LOCATION (exp, gimple_location (stmt));
+  walk_tree (&exp, set_expr_location_r, stmt, NULL);
 
   /* Ensure RTL is created for debug args.  */
   if (decl && DECL_HAS_DEBUG_ARGS_P (decl))
@@ -2097,8 +2107,8 @@ expand_gimple_stmt_1 (gimple stmt)
            tree rhs = gimple_assign_rhs1 (stmt);
            gcc_assert (get_gimple_rhs_class (gimple_expr_code (stmt))
                        == GIMPLE_SINGLE_RHS);
-           if (gimple_has_location (stmt) && CAN_HAVE_LOCATION_P (rhs))
-             SET_EXPR_LOCATION (rhs, gimple_location (stmt));
+           walk_tree (&rhs, set_expr_location_r, stmt, NULL);
+           walk_tree (&lhs, set_expr_location_r, stmt, NULL);
            if (TREE_CLOBBER_P (rhs))
              /* This is a clobber to mark the going out of scope for
                 this LHS.  */

Reply via email to