Skip to content

Commit 9e08e87

Browse files
Merge pull request #785 from goblint/issue_94
Cleanup reporting of dead code
2 parents c01ca61 + ab670af commit 9e08e87

File tree

11 files changed

+48
-35
lines changed

11 files changed

+48
-35
lines changed

goblint.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dev-repo: "git+https://github.com/goblint/analyzer.git"
6868
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
6969
# also remember to generate/adjust goblint.opam.locked!
7070
pin-depends: [
71-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#c150579b9bcfe60c4f441a9f5ac0122c2501a88c" ]
71+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#54b0c220a9cea4213ff596eadff877a6ec9b00fb" ]
7272
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
7373
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
7474
# quoter workaround reverted for release, so no pin needed

goblint.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ version: "dev"
121121
pin-depends: [
122122
[
123123
"goblint-cil.1.8.2"
124-
"git+https://github.com/goblint/cil.git#c150579b9bcfe60c4f441a9f5ac0122c2501a88c"
124+
"git+https://github.com/goblint/cil.git#54b0c220a9cea4213ff596eadff877a6ec9b00fb"
125125
]
126126
[
127127
"apron.v0.9.13"

goblint.opam.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# on `dune build` goblint.opam will be generated from goblint.opam.template and dune-project
22
# also remember to generate/adjust goblint.opam.locked!
33
pin-depends: [
4-
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#c150579b9bcfe60c4f441a9f5ac0122c2501a88c" ]
4+
[ "goblint-cil.1.8.2" "git+https://github.com/goblint/cil.git#54b0c220a9cea4213ff596eadff877a6ec9b00fb" ]
55
# TODO: add back after release, only pinned for optimization (https://github.com/ocaml-ppx/ppx_deriving/pull/252)
66
[ "ppx_deriving.5.2.1" "git+https://github.com/ocaml-ppx/ppx_deriving.git#0a89b619f94cbbfc3b0fb3255ab4fe5bc77d32d6" ]
77
# quoter workaround reverted for release, so no pin needed

gobview

scripts/update_suite.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def run_testset (testset, cmd, starttime)
367367

368368
def run
369369
filename = File.basename(@path)
370-
cmd = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --enable dbg.print_dead_code --set goblint-dir .goblint-#{@id.sub('/','-')} 2>#{@testset.statsfile}"
370+
cmd = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --set goblint-dir .goblint-#{@id.sub('/','-')} 2>#{@testset.statsfile}"
371371
starttime = Time.now
372372
run_testset(@testset, cmd, starttime)
373373
end
@@ -428,8 +428,8 @@ def create_test_set(lines)
428428

429429
def run
430430
filename = File.basename(@path)
431-
cmd = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --enable dbg.print_dead_code --enable incremental.save --set goblint-dir .goblint-#{@id.sub('/','-')}-incr-save 2>#{@testset.statsfile}"
432-
cmd_incr = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset_incr.warnfile} --set printstats true --enable dbg.print_dead_code --enable incremental.load --set goblint-dir .goblint-#{@id.sub('/','-')}-incr-load 2>#{@testset_incr.statsfile}"
431+
cmd = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --enable incremental.save --set goblint-dir .goblint-#{@id.sub('/','-')}-incr-save 2>#{@testset.statsfile}"
432+
cmd_incr = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset_incr.warnfile} --set printstats true --enable incremental.load --set goblint-dir .goblint-#{@id.sub('/','-')}-incr-load 2>#{@testset_incr.statsfile}"
433433
starttime = Time.now
434434
run_testset(@testset_incr, cmd, starttime)
435435
# apply patch
@@ -472,8 +472,8 @@ def create_test_set(lines)
472472
end
473473
def run ()
474474
filename = File.basename(@path)
475-
cmd1 = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --enable dbg.print_dead_code --set save_run run --set goblint-dir .goblint-#{@id.sub('/','-')}-run-save 2>#{@testset.statsfile}"
476-
cmd2 = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --enable dbg.print_dead_code --conf run/config.json --set save_run '' --set load_run run --set goblint-dir .goblint-#{@id.sub('/','-')}-run-load 2>#{@testset.statsfile}"
475+
cmd1 = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --set save_run run --set goblint-dir .goblint-#{@id.sub('/','-')}-run-save 2>#{@testset.statsfile}"
476+
cmd2 = "#{$goblint} #{filename} #{@params} #{ENV['gobopt']} 1>#{@testset.warnfile} --set printstats true --conf run/config.json --set save_run '' --set load_run run --set goblint-dir .goblint-#{@id.sub('/','-')}-run-load 2>#{@testset.statsfile}"
477477
starttime = Time.now
478478
run_testset(@testset, cmd1, starttime)
479479
run_testset(@testset, cmd2, starttime)

src/framework/control.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let spec_module: (module Spec) Lazy.t = lazy (
2323
|> lift (get_bool "ana.sv-comp.enabled") (module HashconsLifter)
2424
|> lift (get_bool "ana.sv-comp.enabled") (module WitnessConstraints.PathSensitive3)
2525
|> lift (not (get_bool "ana.sv-comp.enabled")) (module PathSensitive2)
26-
|> lift (get_bool "dbg.print_dead_code") (module DeadBranchLifter)
26+
|> lift (get_bool "ana.dead-code.branches") (module DeadBranchLifter)
2727
|> lift true (module DeadCodeLifter)
2828
|> lift (get_bool "dbg.slice.on") (module LevelSliceLifter)
2929
|> lift (get_int "dbg.limit.widen" > 0) (module LimitLifter)
@@ -82,7 +82,7 @@ struct
8282
let dead_locations : unit Deadcode.Locmap.t = Deadcode.Locmap.create 10 in
8383
let module NH = Hashtbl.Make (Node) in
8484
let live_nodes : unit NH.t = NH.create 10 in
85-
let count = ref 0 in (* Is only populated if "dbg.print_dead_code" is true *)
85+
let count = ref 0 in (* Is only populated if "ana.dead-code.lines" or "ana.dead-code.branches" is true *)
8686
let module StringMap = BatMap.Make (String) in
8787
let open BatPrintf in
8888
let live_lines = ref StringMap.empty in
@@ -149,9 +149,9 @@ struct
149149
M.msg_group Warning ~category:Deadcode "Function '%s' has dead code" f msgs
150150
in
151151
let warn_file f = StringMap.iter (warn_func f) in
152-
if get_bool "dbg.print_dead_code" then (
152+
if get_bool "ana.dead-code.lines" then (
153153
if StringMap.is_empty !dead_lines
154-
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 *)
154+
then printf "No lines with dead code found by solver.\n"
155155
else (
156156
StringMap.iter warn_file !dead_lines; (* populates count by side-effect *)
157157
let total_dead = !count + uncalled_fn_loc in
@@ -160,13 +160,14 @@ struct
160160
printf "Total lines (logical LoC): %d\n" (live_count + !count + uncalled_fn_loc); (* We can only give total LoC if we counted dead code *)
161161
);
162162
let str = function true -> "then" | false -> "else" in
163+
let cilinserted = function true -> "(possibly inserted by CIL) " | false -> "" in
163164
let report tv (loc, dead) =
164165
match dead, Deadcode.Locmap.find_option Deadcode.dead_branches_cond loc with
165-
| true, Some exp -> M.warn ~loc ~category:Deadcode ~tags:[CWE (if tv then 570 else 571)] "the %s branch over expression '%a' is dead" (str tv) d_exp exp
166-
| true, None -> M.warn ~loc ~category:Deadcode ~tags:[CWE (if tv then 570 else 571)] "an %s branch is dead" (str tv)
166+
| true, Some exp -> M.warn ~loc ~category:Deadcode ~tags:[CWE (if tv then 570 else 571)] "the %s branch %sover expression '%a' is dead" (str tv) (cilinserted loc.synthetic) d_exp exp
167+
| true, None -> M.warn ~loc ~category:Deadcode ~tags:[CWE (if tv then 570 else 571)] "an %s branch %sis dead" (str tv) (cilinserted loc.synthetic)
167168
| _ -> ()
168169
in
169-
if get_bool "dbg.print_dead_code" then (
170+
if get_bool "ana.dead-code.branches" then (
170171
let by_fst (a,_) (b,_) = Stdlib.compare a b in
171172
Deadcode.Locmap.to_list Deadcode.dead_branches_then |> List.sort by_fst |> List.iter (report true) ;
172173
Deadcode.Locmap.to_list Deadcode.dead_branches_else |> List.sort by_fst |> List.iter (report false) ;
@@ -549,7 +550,7 @@ struct
549550
| GFun (fn, loc) when is_bad_uncalled fn.svar loc->
550551
let cnt = Cilfacade.countLoc fn in
551552
uncalled_dead := !uncalled_dead + cnt;
552-
if get_bool "dbg.uncalled" then
553+
if get_bool "ana.dead-code.functions" then
553554
M.warn ~loc ~category:Deadcode "Function \"%a\" will never be called: %dLoC" CilType.Fundec.pretty fn cnt
554555
| _ -> ()
555556
in
@@ -624,7 +625,7 @@ struct
624625
let local_xml = solver2source_result lh in
625626

626627
let liveness =
627-
if get_bool "dbg.print_dead_code" then
628+
if get_bool "ana.dead-code.lines" || get_bool "ana.dead-code.branches" then
628629
print_dead_code local_xml !uncalled_dead
629630
else
630631
fun _ -> true (* TODO: warn about conflicting options *)

src/maingoblint.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@ let rec option_spec_list: Arg_complete.speclist Lazy.t = lazy (
5151
set_string "outfile" "result";
5252
if get_string "exp.g2html_path" = "" then
5353
set_string "exp.g2html_path" (Fpath.to_string exe_dir);
54-
set_bool "dbg.print_dead_code" true;
5554
set_bool "exp.cfgdot" true;
5655
set_bool "g2html" true;
5756
set_string "result" "fast_xml"
5857
in
5958
let configure_sarif () =
6059
if (get_string "outfile" = "") then
6160
set_string "outfile" "goblint.sarif";
62-
set_bool "dbg.print_dead_code" true;
6361
set_string "result" "sarif"
6462
in
6563
let complete_option_value option s =

src/util/cilfacade.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let isCharType = function
3939

4040
let init () =
4141
initCIL ();
42+
removeBranchingOnConstants := false;
4243
lowerConstants := true;
4344
Mergecil.ignore_merge_conflicts := true;
4445
Mergecil.merge_inlines := get_bool "cil.merge.inlines";

src/util/options.schema.json

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,31 @@
881881
}
882882
},
883883
"additionalProperties": false
884+
},
885+
"dead-code" : {
886+
"title": "ana.dead-code",
887+
"type": "object",
888+
"properties": {
889+
"lines": {
890+
"title": "ana.dead-code.lines",
891+
"description": "Print information about lines of dead code.",
892+
"type": "boolean",
893+
"default": true
894+
},
895+
"branches": {
896+
"title": "ana.dead-code.branches",
897+
"description": "Print information about dead branches.",
898+
"type": "boolean",
899+
"default": true
900+
},
901+
"functions": {
902+
"title": "ana.dead-code.functions",
903+
"description": "Print information about dead (uncalled) functions.",
904+
"type": "boolean",
905+
"default": true
906+
}
907+
},
908+
"additionalProperties": false
884909
}
885910
},
886911
"additionalProperties": false
@@ -1373,12 +1398,6 @@
13731398
},
13741399
"additionalProperties": false
13751400
},
1376-
"uncalled": {
1377-
"title": "dbg.uncalled",
1378-
"description": "Display uncalled functions.",
1379-
"type": "boolean",
1380-
"default": true
1381-
},
13821401
"dump": {
13831402
"title": "dbg.dump",
13841403
"description": "Dumps the results to the given path",
@@ -1433,12 +1452,6 @@
14331452
"type": "boolean",
14341453
"default": false
14351454
},
1436-
"print_dead_code": {
1437-
"title": "dbg.print_dead_code",
1438-
"description": "Print information about dead code",
1439-
"type": "boolean",
1440-
"default": false
1441-
},
14421455
"slice": {
14431456
"title": "dbg.slice",
14441457
"type": "object",

tests/regression/56-witness/03-int-log-short.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
version: heads/int-log-0-g5f8473450-dirty
99
command_line: '''/home/simmo/dev/goblint/sv-comp/goblint/goblint'' ''03-int-log-short.c''
1010
''--enable'' ''witness.yaml.enabled'' ''--set'' ''dbg.debug'' ''true'' ''--set''
11-
''printstats'' ''true'' ''--enable'' ''dbg.print_dead_code'' ''--set'' ''goblint-dir''
11+
''printstats'' ''true'' ''--set'' ''goblint-dir''
1212
''.goblint-56-03'''
1313
task:
1414
input_files:
@@ -37,7 +37,7 @@
3737
version: heads/int-log-0-g5f8473450-dirty
3838
command_line: '''/home/simmo/dev/goblint/sv-comp/goblint/goblint'' ''03-int-log-short.c''
3939
''--enable'' ''witness.yaml.enabled'' ''--set'' ''dbg.debug'' ''true'' ''--set''
40-
''printstats'' ''true'' ''--enable'' ''dbg.print_dead_code'' ''--set'' ''goblint-dir''
40+
''printstats'' ''true'' ''--set'' ''goblint-dir''
4141
''.goblint-56-03'''
4242
task:
4343
input_files:

0 commit comments

Comments
 (0)