From 65eba76cf05b13744599b373a821c3b0e537cc49 Mon Sep 17 00:00:00 2001 From: Michael Schwarz Date: Wed, 5 May 2021 08:18:28 +0200 Subject: [PATCH] Only report total LLoc when dbg.print_dead_code. Otherwise, the dead code count is not initialized. References #94 --- src/framework/control.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/framework/control.ml b/src/framework/control.ml index 49ea3faf84..e3400a9871 100644 --- a/src/framework/control.ml +++ b/src/framework/control.ml @@ -69,7 +69,7 @@ struct let dead_locations : unit Deadcode.Locmap.t = Deadcode.Locmap.create 10 in let module NH = Hashtbl.Make (MyCFG.Node) in let live_nodes : unit NH.t = NH.create 10 in - let count = ref 0 in + let count = ref 0 in (* Is only populated if "dbg.print_dead_code" is true *) let module StringMap = BatMap.Make (String) in let open BatPrintf in let live_lines = ref StringMap.empty in @@ -119,16 +119,16 @@ struct printf "File '%s':\n" f; StringMap.iter print_func in - let total_dead = !count + uncalled_fn_loc in if get_bool "dbg.print_dead_code" then ( if StringMap.is_empty !dead_lines then printf "No lines with dead code found by solver (there might still be dead code removed by CIL).\n" (* TODO https://github.com/goblint/analyzer/issues/94 *) else ( - StringMap.iter print_file !dead_lines; + StringMap.iter print_file !dead_lines; (* populates count by side-effect *) + let total_dead = !count + uncalled_fn_loc in printf "Found dead code on %d line%s%s!\n" total_dead (if total_dead>1 then "s" else "") (if uncalled_fn_loc > 0 then Printf.sprintf " (including %d in uncalled functions)" uncalled_fn_loc else "") - ) + ); + printf "Total lines (logical LoC): %d\n" (live_count + !count + uncalled_fn_loc); (* We can only give total LoC if we counted dead code *) ); - printf "Total lines (logical LoC): %d\n" (live_count + total_dead); let str = function true -> "then" | false -> "else" in let report tv (loc, dead) = if Deadcode.Locmap.mem dead_locations loc then