aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJørgen Kvalsvik <j@lambda.is>2025-03-31 19:03:37 +0200
committerJørgen Kvalsvik <j@lambda.is>2025-03-31 19:47:14 +0200
commitde742091f4df997f426d99bcfed3c44914788033 (patch)
tree3ffdfef4972b82709cee02f65b3a077e0de2daf5 /gcc
parent44289d258a970e39059afa33d2a44d16ba41d3f2 (diff)
downloadgcc-de742091f4df997f426d99bcfed3c44914788033.zip
gcc-de742091f4df997f426d99bcfed3c44914788033.tar.gz
gcc-de742091f4df997f426d99bcfed3c44914788033.tar.bz2
Only write gcov when file output is on [PR119553]
gcov_write_* functions must be guarded so they only are called when output_to_file is true, like for -fcondition-coverage, otherwise it triggers an invalid read as detected by valgrind. The gcno file is mostly written to from profile.cc, so it doesn't make too much sense to hide it in path-coverage.cc. The find_paths name was a bit imprecise, and is renamed to instrument_prime_paths. PR gcov-profile/119553 gcc/ChangeLog: * path-coverage.cc (find_paths): Return path count, don't write to gcno, and rename to ... (instrument_prime_paths): ... this. * profile.cc (branch_prob): Write path counts to gcno.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/path-coverage.cc15
-rw-r--r--gcc/profile.cc12
2 files changed, 16 insertions, 11 deletions
diff --git a/gcc/path-coverage.cc b/gcc/path-coverage.cc
index 55b3929..55058fd 100644
--- a/gcc/path-coverage.cc
+++ b/gcc/path-coverage.cc
@@ -504,8 +504,8 @@ flush_on_gsi (gimple_stmt_iterator *gsi, size_t bucket, tree local, tree mask,
bit N%64 in bucket N/64. For large functions, an individual basic block
will only be part of a small subset of paths, and by extension buckets and
local counters. Only the necessary counters are read and written. */
-void
-find_paths (struct function *fn)
+unsigned
+instrument_prime_paths (struct function *fn)
{
mark_dfs_back_edges (fn);
vec<vec<int>> paths = find_prime_paths (fn);
@@ -515,7 +515,7 @@ find_paths (struct function *fn)
warning_at (fn->function_start_locus, OPT_Wcoverage_too_many_paths,
"paths exceeding limit, giving up path coverage");
release_vec_vec (paths);
- return;
+ return 0;
}
tree gcov_type_node = get_gcov_type ();
@@ -526,14 +526,9 @@ find_paths (struct function *fn)
if (!coverage_counter_alloc (GCOV_COUNTER_PATHS, nbuckets))
{
release_vec_vec (paths);
- return;
+ return 0;
}
- gcov_position_t offset {};
- offset = gcov_write_tag (GCOV_TAG_PATHS);
- gcov_write_unsigned (paths.length ());
- gcov_write_length (offset);
-
hash_map <edge_hash, uint64_t> ands;
hash_map <block_hash, uint64_t> iors;
hash_map <block_hash, uint64_t> flushes;
@@ -771,6 +766,8 @@ find_paths (struct function *fn)
}
}
+ const unsigned npaths = paths.length ();
blocks.release ();
release_vec_vec (paths);
+ return npaths;
}
diff --git a/gcc/profile.cc b/gcc/profile.cc
index 0b222cf..c0f5097 100644
--- a/gcc/profile.cc
+++ b/gcc/profile.cc
@@ -1611,9 +1611,17 @@ branch_prob (bool thunk)
instrument_values (values);
}
- void find_paths (struct function*);
+ unsigned instrument_prime_paths (struct function*);
if (path_coverage_flag)
- find_paths (cfun);
+ {
+ const unsigned npaths = instrument_prime_paths (cfun);
+ if (output_to_file)
+ {
+ gcov_position_t offset = gcov_write_tag (GCOV_TAG_PATHS);
+ gcov_write_unsigned (npaths);
+ gcov_write_length (offset);
+ }
+ }
free_aux_for_edges ();