Skip to content

Commit

Permalink
Fix -flto and RTS coverage detection
Browse files Browse the repository at this point in the history
Suppress a spurious clang warning
  • Loading branch information
Alasdair committed Apr 26, 2024
1 parent 6534384 commit eb174bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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':
Expand Down
6 changes: 2 additions & 4 deletions src/sail_c_backend/c_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit eb174bf

Please sign in to comment.