]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
profile: Another musttail fix [PR119618]
authorJakub Jelinek <jakub@redhat.com>
Fri, 4 Apr 2025 18:53:19 +0000 (20:53 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 4 Apr 2025 18:53:19 +0000 (20:53 +0200)
As the following testcase shows, sometimes we can have debug stmts
after a musttail call and profile.cc in that case would incorrectly
allow the edge from that, causing musttail error and -fcompare-debug
failure (because if there are no debug stmts after it, then musttail
is found there and the edge is ignored).

The following patch uses gsi_last_nondebug_bb instead of gsi_last_bb
to find the musttail call.  And so that we don't uselessly skip over
debug stmts at the end of many bbs, the patch limits it to
cfun->has_musttail functions.

2025-04-04  Jakub Jelinek  <jakub@redhat.com>

PR gcov-profile/119618
* profile.cc (branch_prob): Only check for musttail calls if
cfun->has_musttail.  Use gsi_last_nondebug_bb instead of gsi_last_bb.

* c-c++-common/pr119618.c: New test.

gcc/profile.cc
gcc/testsuite/c-c++-common/pr119618.c [new file with mode: 0644]

index 550c85b9742c270cbe1d1d7b70c1b701cef5124e..6234dd2d4e2d8c82730292713eaed321f70fd1bf 100644 (file)
@@ -1341,9 +1341,10 @@ branch_prob (bool thunk)
          ignored_edges++;
        }
       /* Ignore edges after musttail calls.  */
-      if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
+      if (cfun->has_musttail
+         && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
        {
-         gimple_stmt_iterator gsi = gsi_last_bb (e->src);
+         gimple_stmt_iterator gsi = gsi_last_nondebug_bb (e->src);
          gimple *stmt = gsi_stmt (gsi);
          if (stmt
              && is_gimple_call (stmt)
diff --git a/gcc/testsuite/c-c++-common/pr119618.c b/gcc/testsuite/c-c++-common/pr119618.c
new file mode 100644 (file)
index 0000000..a56e669
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR gcov-profile/119618 */
+/* { dg-do compile { target musttail } } */
+/* { dg-options "-fcompare-debug -fprofile-generate -O1" } */
+/* { dg-require-profiling "-fprofile-generate" } */
+
+struct S { char s; };
+int foo (void);
+int *(*fn) (void);
+
+int *
+bar (void)
+{
+  if (foo ())
+    return 0;
+  {
+    struct S s;
+    do
+      [[gnu::musttail]] return fn ();
+    while (0);
+  }
+}