tree: Fix -fcompare-debug issues due to protected_set_expr_location [PR94323]
authorJakub Jelinek <jakub@redhat.com>
Thu, 26 Mar 2020 09:35:52 +0000 (10:35 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 26 Mar 2020 09:35:52 +0000 (10:35 +0100)
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.

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/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/debug/pr94323.C [new file with mode: 0644]
gcc/tree.c

index 8005e1a91f7cccdaf0991e6afb9b49fc0751e387..cc7f4d4ab377786a18d190d8c656c2bd053568b0 100644 (file)
@@ -1,5 +1,9 @@
 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.
+
        PR debug/94281
        * gimple.h (gimple_seq_first_nondebug_stmt): New function.
        (gimple_seq_last_nondebug_stmt): Don't return NULL if seq contains
index 65f32a3eb1d0c9012a1f9602aaadddf399827827..4d73d481a6477a7eb5b95a5fe42a8d6bd06be711 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/94323
+       * g++.dg/debug/pr94323.C: New test.
+
 2020-03-26  Martin Liska  <mliska@suse.cz>
 
        PR testsuite/94334
diff --git a/gcc/testsuite/g++.dg/debug/pr94323.C b/gcc/testsuite/g++.dg/debug/pr94323.C
new file mode 100644 (file)
index 0000000..eac81a3
--- /dev/null
@@ -0,0 +1,13 @@
+// PR debug/94323
+// { dg-do compile }
+// { dg-options "-O2 -fcompare-debug" }
+
+volatile int a;
+
+void
+foo ()
+{
+  ({
+     a;
+   });
+}
index f38dfffc16ebedf3e2dfd6a9fafddeb534aab864..63dc6730b2b637182aa3476aa0738d682f7b8102 100644 (file)
@@ -5146,6 +5146,33 @@ protected_set_expr_location (tree t, location_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.  */