]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PR middle-end/102764
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 20 Oct 2021 08:42:56 +0000 (10:42 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Wed, 20 Oct 2021 08:46:37 +0000 (10:46 +0200)
This is a regression present on the mainline in the form of -fcompare-debug
failure at -O3 on a compiler-generated testcase.  Fixed by disregarding a
debug statement in the last position of a basic block to reset the current
location for the outgoing edges.

gcc/
PR middle-end/102764
* cfgexpand.c (expand_gimple_basic_block): Disregard a final debug
statement to reset the current location for the outgoing edges.

gcc/testsuite/
* gcc.dg/pr102764.c: New test.

gcc/cfgexpand.c
gcc/testsuite/gcc.dg/pr102764.c [new file with mode: 0644]

index 03260b019e5685aee033bee9f21e29aea43647d6..8b067f9d84871e77c16a878e35d85db68b9c581b 100644 (file)
@@ -6090,7 +6090,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
   /* Expand implicit goto and convert goto_locus.  */
   FOR_EACH_EDGE (e, ei, bb->succs)
     {
-      if (e->goto_locus != UNKNOWN_LOCATION || !stmt)
+      if (e->goto_locus != UNKNOWN_LOCATION || !stmt || is_gimple_debug (stmt))
        set_curr_insn_location (e->goto_locus);
       if ((e->flags & EDGE_FALLTHRU) && e->dest != bb->next_bb)
        {
diff --git a/gcc/testsuite/gcc.dg/pr102764.c b/gcc/testsuite/gcc.dg/pr102764.c
new file mode 100644 (file)
index 0000000..ea1c634
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR middle-end/102764 */
+/* Reported by Chengnian Sun <cnsun@uwaterloo.ca> */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -fcompare-debug" } */
+
+volatile int a;
+
+void main (void)
+{
+  for (int i = 0; i < 1000; i++)
+    if (i % 17)
+      a++;
+}