public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree: Fix -fcompare-debug issues due to protected_set_expr_location [PR94323]
@ 2020-03-26  9:04 Jakub Jelinek
  2020-03-26  9:14 ` Richard Biener
  0 siblings, 1 reply; 19+ messages in thread
From: Jakub Jelinek @ 2020-03-26  9:04 UTC (permalink / raw)
  To: Richard Biener, Jason Merrill; +Cc: gcc-patches

Hi!

The following testcase FAILs since recently when the C++ FE started calling
protected_set_expr_location more often.
With -g, it is called on a STATEMENT_LIST that contains a DEBUG_BEGIN_STMT
and CLEANUP_POINT_EXPR, and as STATEMENT_LISTs have !CAN_HAVE_LOCATION_P,
nothing is set.  Without -g, it is called instead on the CLEANUP_POINT_EXPR
directly and changes its location.

The following patch recurses on the single non-DEBUG_BEGIN_STMT statement
of a STATEMENT_LIST if any to make the two behave the same.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-03-26  Jakub Jelinek  <jakub@redhat.com>

	PR debug/94323
	* tree.c (protected_set_expr_location): Recurse on STATEMENT_LIST
	that contains exactly one non-DEBUG_BEGIN_STMT statement.

	* g++.dg/debug/pr94323.C: New test.

--- gcc/tree.c.jj	2020-03-23 19:46:45.552448327 +0100
+++ gcc/tree.c	2020-03-25 17:22:12.438904778 +0100
@@ -5146,6 +5146,33 @@ protected_set_expr_location (tree t, loc
 {
   if (CAN_HAVE_LOCATION_P (t))
     SET_EXPR_LOCATION (t, loc);
+  else if (t && TREE_CODE (t) == STATEMENT_LIST)
+    {
+      /* With -gstatement-frontiers we could have a STATEMENT_LIST with
+	 DEBUG_BEGIN_STMT(s) and only a single other stmt, which with
+	 -g wouldn't be present and we'd have that single other stmt
+	 directly instead.  */
+      struct tree_statement_list_node *n = STATEMENT_LIST_HEAD (t);
+      if (!n)
+	return;
+      while (TREE_CODE (n->stmt) == DEBUG_BEGIN_STMT)
+	{
+	  n = n->next;
+	  if (!n)
+	    return;
+	}
+      tree t2 = n->stmt;
+      do
+	{
+	  n = n->next;
+	  if (!n)
+	    {
+	      protected_set_expr_location (t2, loc);
+	      return;
+	    }
+	}
+      while (TREE_CODE (n->stmt) == DEBUG_BEGIN_STMT);
+    }
 }
 
 /* Data used when collecting DECLs and TYPEs for language data removal.  */
--- gcc/testsuite/g++.dg/debug/pr94323.C.jj	2020-03-25 17:17:49.857819078 +0100
+++ gcc/testsuite/g++.dg/debug/pr94323.C	2020-03-25 17:17:17.533300951 +0100
@@ -0,0 +1,13 @@
+// PR debug/94323
+// { dg-do compile }
+// { dg-options "-O2 -fcompare-debug" }
+
+volatile int a;
+
+void
+foo ()
+{
+  ({
+     a;
+   });
+}

	Jakub


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-03-30 11:13 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26  9:04 [PATCH] tree: Fix -fcompare-debug issues due to protected_set_expr_location [PR94323] Jakub Jelinek
2020-03-26  9:14 ` Richard Biener
2020-03-26  9:16   ` Jakub Jelinek
2020-03-26  9:24     ` Richard Biener
2020-03-26 10:43       ` Jakub Jelinek
2020-03-26 10:47         ` Richard Biener
2020-03-26 23:41         ` Alexandre Oliva
2020-03-26 23:56           ` Jakub Jelinek
2020-03-27  1:21             ` Alexandre Oliva
2020-03-27  8:32             ` Richard Biener
2020-03-27  8:48               ` Jakub Jelinek
2020-03-27  9:57                 ` Richard Biener
2020-03-27 15:32                   ` Jakub Jelinek
2020-03-27 20:09                     ` Richard Biener
2020-03-30 10:21                       ` Jakub Jelinek
2020-03-30 10:44                         ` Richard Biener
2020-03-30 11:03                           ` Jakub Jelinek
2020-03-30 11:09                             ` Richard Biener
2020-03-30 11:13                               ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).