From d2e5aa0ab2c70984a92412c406ef7f3fb15f1cc2 Mon Sep 17 00:00:00 2001 From: Alasdair Date: Fri, 26 Apr 2024 14:37:12 +0100 Subject: [PATCH] Fix -flto and RTS coverage detection Suppress a spurious clang warning --- lib/rts.c | 4 ++-- src/sail_c_backend/c_backend.ml | 6 ++---- test/sailcov/run_tests.py | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/rts.c b/lib/rts.c index 466ff794e..95dba11ba 100644 --- a/lib/rts.c +++ b/lib/rts.c @@ -78,7 +78,7 @@ extern "C" { #endif -extern void sail_rts_set_coverage_file(char *output_file); +extern void (*sail_rts_set_coverage_file)(const char *); static uint64_t g_elf_entry; uint64_t g_cycle_count = 0; @@ -725,7 +725,7 @@ int process_arguments(int argc, char *argv[]) break; case 'c': - if (&sail_rts_set_coverage_file) { + if (sail_rts_set_coverage_file != NULL) { sail_rts_set_coverage_file(optarg); } else { fprintf(stderr, "Ignoring flag -c %s. Requires the model to be compiled with coverage\n", optarg); diff --git a/src/sail_c_backend/c_backend.ml b/src/sail_c_backend/c_backend.ml index 8b6604fc7..1740078d2 100644 --- a/src/sail_c_backend/c_backend.ml +++ b/src/sail_c_backend/c_backend.ml @@ -2009,10 +2009,8 @@ let compile_ast env effect_info output_chan c_includes ast = let header = string "#include \"sail_coverage.h\"" in (* Generate a hook for the RTS to call if we have coverage enabled, so it can set the output file with an option. *) - let coverage_hook = - string "void sail_rts_set_coverage_file(char *output_file) { sail_set_coverage_file(output_file); }" - in - let no_coverage_hook = string "void (*sail_rts_set_coverage_file)(char *) = NULL;" in + let coverage_hook = string "void (*sail_rts_set_coverage_file)(const char *) = &sail_set_coverage_file;" in + let no_coverage_hook = string "void (*sail_rts_set_coverage_file)(const char *) = NULL;" in match !opt_branch_coverage with | Some _ -> if !opt_no_rts then [header] else [header; coverage_hook] | None -> if !opt_no_rts then [] else [no_coverage_hook] diff --git a/test/sailcov/run_tests.py b/test/sailcov/run_tests.py index 72c5de42b..9445ff3b6 100755 --- a/test/sailcov/run_tests.py +++ b/test/sailcov/run_tests.py @@ -43,7 +43,7 @@ def test_sailcov(): step('./{}.bin -c {}.taken'.format(basename, basename)) step('{} --all {}.branches --taken {}.taken {}'.format(sailcov, basename, basename, filename)) step('diff {}.html {}.expect'.format(basename, basename)) - step('rm {}.taken {}.bin'.format(basename, basename)) + step('rm {}.taken {}.bin {}.branches'.format(basename, basename, basename)) print_ok(filename) sys.exit() results.collect(tests)