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 a31c72e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 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) {

This comment has been minimized.

Copy link
@arichardson

arichardson Apr 26, 2024

Contributor

Is this address of operator needed? Surely you want to check the value of the pointer not the address (which only matters for weak symbols)?

This comment has been minimized.

Copy link
@Alasdair

Alasdair Apr 26, 2024

Author Collaborator

Yep, should be fixed now.

My original attempt to do this did rely on weak symbols, hence the &

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
4 changes: 2 additions & 2 deletions src/sail_c_backend/c_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a31c72e

Please sign in to comment.