https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121074

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Well, so it's coverage_init opening the gcno file which is indeed never closed
and then afdo trying to open it's own in the afdo_offline pass.

#0  gcov_open (name=0x4eb7b60 "a-t.gcno", mode=-1)
    at /space/rguenther/src/gcc-clean/gcc/gcov-io.cc:166
#1  0x000000000130a038 in coverage_init (filename=0x4f10940 "a-t")
    at /space/rguenther/src/gcc-clean/gcc/coverage.cc:1334
#2  0x0000000001a994ff in do_compile ()
    at /space/rguenther/src/gcc-clean/gcc/toplev.cc:2218
#3  0x0000000001a9999b in toplev::main (this=0x7fffffffdb9a, argc=24, 
    argv=0x7fffffffdcc8) at /space/rguenther/src/gcc-clean/gcc/toplev.cc:2389
#4  0x0000000003821d5a in main (argc=24, argv=0x7fffffffdcc8)
    at /space/rguenther/src/gcc-clean/gcc/main.cc:39

it seems that AFDO and -ftest-coverage should simply conflict?  Or the
single-file restriction of the gcov API needs to be lifted.

There's an overlap I guess - calling coverage_finish from ipa_tree_profile
would not help:

  NEXT_PASS (pass_ipa_auto_profile);
  PUSH_INSERT_PASSES_WITHIN (pass_ipa_auto_profile)
      NEXT_PASS (pass_feedback_split_functions);
  POP_INSERT_PASSES ()
  NEXT_PASS (pass_ipa_tree_profile);
  PUSH_INSERT_PASSES_WITHIN (pass_ipa_tree_profile)
      NEXT_PASS (pass_feedback_split_functions);
  POP_INSERT_PASSES ()
  NEXT_PASS (pass_ipa_free_fn_summary, true /* small_p */);
  NEXT_PASS (pass_ipa_increase_alignment);
  NEXT_PASS (pass_ipa_tm);
  NEXT_PASS (pass_ipa_lower_emutls);
  NEXT_PASS (pass_ipa_asm_lgen);
  TERMINATE_PASS_LIST (all_small_ipa_passes)

we're currently calling coverage_finish after all_small_ipa_passes.

IMO a sorry() from finish_options would be appropriate?

On the 15 branch we did either coverage or AFDO with reading the data at
coverage_init time:

  if (flag_auto_profile)
    read_autofdo_file ();
  else if (flag_branch_probabilities)
    read_counts_file ();

but now we consume both?  Part of a fix might possibly want to include

diff --git a/gcc/coverage.cc b/gcc/coverage.cc
index f2a095a1279..0f7fe09d865 100644
--- a/gcc/coverage.cc
+++ b/gcc/coverage.cc
@@ -1316,7 +1316,7 @@ coverage_init (const char *filename)
   strcpy (da_file_name + prefix_len + len, GCOV_DATA_SUFFIX);

   bbg_file_stamp = local_tick;
-  if (flag_branch_probabilities)
+  if (flag_branch_probabilities && !flag_auto_profile)
     read_counts_file ();

   /* Name of bbg file.  */

but the problematical part is the delayed read_autofdo_file which happens
when the coverage file is still open.  So it's going to be a functional
regression.  I'm not sure gcov supports closing & re-opening easily.

Reply via email to