https://gcc.gnu.org/g:340c45dc16a0a75a477192a2baaf28235be7f520

commit r16-7180-g340c45dc16a0a75a477192a2baaf28235be7f520
Author: Jørgen Kvalsvik <[email protected]>
Date:   Wed Jan 28 20:33:21 2026 +0100

    Permit const counters in flush_on_edges [PR123855]
    
    Relax the (accidental) requirement and permit that function-local
    counters don't have SSA names.  We really only look up the def
    statement to check if it is a phi node, in which case we need to
    resolve the counter from there.  This obviously doesn't apply when it
    is a constant.
    
            PR gcov-profile/123855
    
    gcc/ChangeLog:
    
            * path-coverage.cc (flush_on_edges): Only look up SSA name def
            stmt when counter is non-const.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.misc-tests/gcov-pr123855.c: New test.

Diff:
---
 gcc/path-coverage.cc                         |  4 ++--
 gcc/testsuite/gcc.misc-tests/gcov-pr123855.c | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/path-coverage.cc b/gcc/path-coverage.cc
index 7ce662ce0077..68a30d5a8ee3 100644
--- a/gcc/path-coverage.cc
+++ b/gcc/path-coverage.cc
@@ -379,8 +379,8 @@ void
 flush_on_edges (basic_block bb, size_t bucket, tree local, tree mask,
                tree atomic_ior, tree gcov_type_node)
 {
-  gimple *def = SSA_NAME_DEF_STMT (local);
-  gphi *phi = dyn_cast <gphi *> (def);
+  gimple *def = !constant_p (local) ? SSA_NAME_DEF_STMT (local) : NULL;
+  gphi *phi = safe_dyn_cast <gphi *> (def);
 
   tree relaxed = nullptr;
   if (atomic_ior)
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-pr123855.c 
b/gcc/testsuite/gcc.misc-tests/gcov-pr123855.c
new file mode 100644
index 000000000000..16fc27a850ff
--- /dev/null
+++ b/gcc/testsuite/gcc.misc-tests/gcov-pr123855.c
@@ -0,0 +1,13 @@
+/* { dg-options "--coverage -fpath-coverage" } */
+
+__attribute__((__returns_twice__)) void
+foo ()
+{
+  foo ();
+  for (;;)
+    ;
+}
+
+int main () {}
+
+/* { dg-final { run-gcov prime-paths gcov-pr123855.c } } */

Reply via email to