[SFN] propagate single-nondebug-stmt's side effects to enclosing list
authorAlexandre Oliva <aoliva@redhat.com>
Thu, 21 Dec 2017 18:14:06 +0000 (18:14 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Thu, 21 Dec 2017 18:14:06 +0000 (18:14 +0000)
Statements without side effects, preceded by debug begin stmt markers,
would become a statement list with side effects, although the stmt on
its own would be extracted from the list and remain not having side
effects.  This causes debug info and possibly codegen differences.
This patch fixes it, identifying the situation in which the stmt would
have been extracted from the stmt list, and propagating the side
effects flag from the stmt to the list.

for  gcc/ChangeLog

PR debug/83419
* c-family/c-semantics.c (pop_stmt_list): Propagate side
effects from single nondebug stmt to container list.

for  gcc/testsuite/ChangeLog

PR debug/83419
* gcc.dg/pr83419.c: New.

From-SVN: r255947

gcc/ChangeLog
gcc/c-family/c-semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr83419.c [new file with mode: 0644]

index d3c4063a5ce784992492f7b2ac7e3f6ad7afb44b..2851eb67cc473f55632b44a64a28a137226e4302 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-21  Alexandre Oliva <aoliva@redhat.com>
+
+       PR debug/83419
+       * c-family/c-semantics.c (pop_stmt_list): Propagate side
+       effects from single nondebug stmt to container list.
+
 2017-12-21  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * config/aarch64/aarch64.c (aarch64_expand_vector_init): Modify code
index cd872d8ac740592f1201096c3acd7a3bef36e9a6..3a972c32c8ea3641afa25a31a964052fe7860e33 100644 (file)
@@ -96,6 +96,15 @@ pop_stmt_list (tree t)
              t = l;
              tsi_link_before (&i, u, TSI_SAME_STMT);
            }
+         while (!tsi_end_p (i)
+                && TREE_CODE (tsi_stmt (i)) == DEBUG_BEGIN_STMT)
+           tsi_next (&i);
+         /* If there's only one nondebug stmt in the list, we'd have
+            extracted the stmt and dropped the list, and we'd take
+            TREE_SIDE_EFFECTS from that statement, so keep the list's
+            TREE_SIDE_EFFECTS in sync.  */
+         if (tsi_one_before_end_p (i))
+           TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (tsi_stmt (i));
        }
     }
 
index 7171973d9699180c5b29326fd010dbd63a1b8bf9..8cc163adac0e0fb3c358eaa5421b9c93e6a91443 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-21  Alexandre Oliva <aoliva@redhat.com>
+
+       PR debug/83419
+       * gcc.dg/pr83419.c: New.
+
 2017-12-21  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * gcc.target/aarch64/vect-slp-dup.c: New.
diff --git a/gcc/testsuite/gcc.dg/pr83419.c b/gcc/testsuite/gcc.dg/pr83419.c
new file mode 100644 (file)
index 0000000..3d4f1d2
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR debug/83419 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcompare-debug" } */
+
+int a, b;
+void foo (int, ...);
+
+void
+bar (void)
+{
+  if (a || 1 == b)
+    foo (1);
+  else
+    0;
+  foo (1, 0);
+}