Hi!

On Fri, Apr 26, 2019 at 09:31:36AM -0600, Jeff Law wrote:
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Thanks, committed to trunk now.

> > I'll work on a C++ FE version of this next (needed as well).

Here is the C++ FE version of this patch, bootstrapped/regtested on
x86_64-linux and i686-linux and tested with the same testcases.

For some strange reason the C++ FE does that
protected_set_expr_location (incr, start_locus);
on the incr expression, so the patch also uses that locus for the
corresponding DEBUG_BEGIN_STMT instead of trying to figure out
original locus for the incr.

Ok for trunk?

2019-04-26  Jakub Jelinek  <ja...@redhat.com>

        PR debug/90197
        * cp-gimplify.c (genericize_cp_loop): Emit a DEBUG_BEGIN_STMT
        before the condition (or if missing or constant non-zero at the end
        of the loop.  Emit a DEBUG_BEGIN_STMT before the increment expression
        if any.

--- gcc/cp/cp-gimplify.c.jj     2019-03-06 19:45:40.367751642 +0100
+++ gcc/cp/cp-gimplify.c        2019-04-25 13:03:17.438538650 +0200
@@ -241,6 +241,7 @@ genericize_cp_loop (tree *stmt_p, locati
   tree blab, clab;
   tree exit = NULL;
   tree stmt_list = NULL;
+  tree debug_begin = NULL;
 
   protected_set_expr_location (incr, start_locus);
 
@@ -253,6 +254,13 @@ genericize_cp_loop (tree *stmt_p, locati
   cp_walk_tree (&body, cp_genericize_r, data, NULL);
   *walk_subtrees = 0;
 
+  if (MAY_HAVE_DEBUG_MARKER_STMTS
+      && (!cond || !integer_zerop (cond)))
+    {
+      debug_begin = build0 (DEBUG_BEGIN_STMT, void_type_node);
+      SET_EXPR_LOCATION (debug_begin, cp_expr_loc_or_loc (cond, start_locus));
+    }
+
   if (cond && TREE_CODE (cond) != INTEGER_CST)
     {
       /* If COND is constant, don't bother building an exit.  If it's false,
@@ -265,10 +273,24 @@ genericize_cp_loop (tree *stmt_p, locati
     }
 
   if (exit && cond_is_first)
-    append_to_statement_list (exit, &stmt_list);
+    {
+      append_to_statement_list (debug_begin, &stmt_list);
+      debug_begin = NULL_TREE;
+      append_to_statement_list (exit, &stmt_list);
+    }
   append_to_statement_list (body, &stmt_list);
   finish_bc_block (&stmt_list, bc_continue, clab);
-  append_to_statement_list (incr, &stmt_list);
+  if (incr)
+    {
+      if (MAY_HAVE_DEBUG_MARKER_STMTS)
+       {
+         tree d = build0 (DEBUG_BEGIN_STMT, void_type_node);
+         SET_EXPR_LOCATION (d, start_locus);
+         append_to_statement_list (d, &stmt_list);
+       }
+      append_to_statement_list (incr, &stmt_list);
+    }
+  append_to_statement_list (debug_begin, &stmt_list);
   if (exit && !cond_is_first)
     append_to_statement_list (exit, &stmt_list);
 


        Jakub

Reply via email to