diff --git a/infer/src/checkers/liveness.ml b/infer/src/checkers/liveness.ml index 94633a195..7c5171409 100644 --- a/infer/src/checkers/liveness.ml +++ b/infer/src/checkers/liveness.ml @@ -77,11 +77,17 @@ let checker {Callbacks.tenv; summary; proc_desc} : Specs.summary = | _ -> () in - List.iter (CFG.nodes cfg) ~f:(fun node -> - (* note: extract_pre grabs the post, since the analysis is backward *) - match Analyzer.extract_pre (CFG.id node) invariant_map with - | Some live_vars - -> List.iter ~f:(report_dead_store live_vars) (CFG.instrs node) - | None - -> () ) ; + let report_on_node node = + List.iter (CFG.instr_ids node) ~f:(fun (instr, node_id_opt) -> + match node_id_opt with + | Some node_id -> ( + match Analyzer.extract_pre node_id invariant_map with + | Some live_vars + -> report_dead_store live_vars instr + | None + -> () ) + | None + -> () ) + in + List.iter (CFG.nodes cfg) ~f:report_on_node ; summary diff --git a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp index 2ce2f29b1..34a0552b8 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp +++ b/infer/tests/codetoanalyze/cpp/liveness/dead_stores.cpp @@ -31,6 +31,21 @@ void dead_pointer_bad() { int* x = # } +void plus_plus1_bad() { + int i = 0; + ++i; +} + +void plus_plus2_bad() { + int i = 0; + i++; +} + +int plus_plus3_bad() { + int i = 0; + return i++; +} + int return_ok() { int x = 5; return x; @@ -85,6 +100,19 @@ int* assign_pointer2_ok() { void by_ref_ok(int& ref) { ref = 7; } +int plus_plus_ok() { + int x = 0; + return ++x; +} + +int plus_plus_loop_ok(int n) { + int i; + for (i = 0; i < n; i++) { + i++; + } + return i; +} + char* global; void FP_assign_array_tricky_ok() { diff --git a/infer/tests/codetoanalyze/cpp/liveness/issues.exp b/infer/tests/codetoanalyze/cpp/liveness/issues.exp index 5fed35731..d3e683524 100644 --- a/infer/tests/codetoanalyze/cpp/liveness/issues.exp +++ b/infer/tests/codetoanalyze/cpp/liveness/issues.exp @@ -2,5 +2,8 @@ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::FP_assign_array_tricky_ codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_pointer_bad, 2, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::dead_then_live_bad, 1, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::easy_bad, 0, DEAD_STORE, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus1_bad, 2, DEAD_STORE, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus2_bad, 2, DEAD_STORE, [Write of unused value] +codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::plus_plus3_bad, 2, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::reassign_param_bad, 0, DEAD_STORE, [Write of unused value] codetoanalyze/cpp/liveness/dead_stores.cpp, dead_stores::use_then_dead_bad, 3, DEAD_STORE, [Write of unused value]