From a31c72e4b69d5dd6656e35f4bdc92b54b74aa0a0 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 | 7 +++++-- src/sail_c_backend/c_backend.ml | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/rts.c b/lib/rts.c index 466ff794e..e90f3df9d 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,11 +725,14 @@ int process_arguments(int argc, char *argv[]) break; case 'c': - if (&sail_rts_set_coverage_file) { + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wtautological-pointer-compare" + 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); } + #pragma clang diagnostic pop break; case 'v': diff --git a/src/sail_c_backend/c_backend.ml b/src/sail_c_backend/c_backend.ml index 8b6604fc7..1ad2d9b17 100644 --- a/src/sail_c_backend/c_backend.ml +++ b/src/sail_c_backend/c_backend.ml @@ -2010,9 +2010,9 @@ let compile_ast env effect_info output_chan c_includes ast = (* 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); }" + 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)(char *) = NULL;" 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]