[Hoisting] Fix hoisting of void functions

Reviewed By: mbouaziz

Differential Revision: D10105698

fbshipit-source-id: 56a91dbd4
master
Ezgi Çiçek 6 years ago committed by Facebook Github Bot
parent 2f7e4563c6
commit aca0b8e130

@ -7,6 +7,7 @@
open! IStd
module L = Logging
module InvariantVars = AbstractDomain.FiniteSet (Var)
module VarsInLoop = AbstractDomain.FiniteSet (Var)
module LoopNodes = AbstractDomain.FiniteSet (Procdesc.Node)
module Models = InvariantModels
@ -72,17 +73,23 @@ let get_vars_in_loop loop_nodes =
| Sil.Load (id, exp_rhs, _, _) ->
Var.get_all_vars_in_exp exp_rhs
|> Sequence.fold
~init:(InvariantVars.add (Var.of_id id) acc)
~f:(fun acc var -> InvariantVars.add var acc)
~init:(VarsInLoop.add (Var.of_id id) acc)
~f:(fun acc var -> VarsInLoop.add var acc)
| Sil.Store (exp_lhs, _, exp_rhs, _) ->
Var.get_all_vars_in_exp exp_rhs
|> Sequence.append (Var.get_all_vars_in_exp exp_lhs)
|> Sequence.fold ~init:acc ~f:(fun acc var -> InvariantVars.add var acc)
(* function calls are ignored at the moment *)
|> Sequence.fold ~init:acc ~f:(fun acc var -> VarsInLoop.add var acc)
| Sil.Call ((ret_id, _), _, args, _, _) ->
List.fold
~init:(VarsInLoop.add (Var.of_id ret_id) acc)
~f:(fun acc (arg_exp, _) ->
Var.get_all_vars_in_exp arg_exp
|> Sequence.fold ~init:acc ~f:(fun acc var -> VarsInLoop.add var acc) )
args
| _ ->
acc )
~init:acc )
loop_nodes InvariantVars.empty
loop_nodes VarsInLoop.empty
(* A variable is invariant if

@ -172,4 +172,15 @@ class Hoist {
}
return k;
}
void dumb_foo() {
int k = 0;
k++;
}
void void_hoist(int size) {
for (int i = 0; i < size; i++) {
dumb_foo();
}
}
}

@ -7,3 +7,4 @@ codetoanalyze/java/hoisting/Hoist.java, Hoist.reassigned_temp_hoist(int):void, 5
codetoanalyze/java/hoisting/Hoist.java, Hoist.two_function_call_hoist(int):void, 4, INVARIANT_CALL, no_bucket, ERROR, [Loop-invariant call to int Hoist.foo(int,int) at line 35]
codetoanalyze/java/hoisting/Hoist.java, Hoist.two_function_call_hoist(int):void, 4, INVARIANT_CALL, no_bucket, ERROR, [Loop-invariant call to int Hoist.bar(int) at line 35]
codetoanalyze/java/hoisting/Hoist.java, Hoist.used_in_loop_body_before_def_temp_hoist(int,int[]):void, 6, INVARIANT_CALL, no_bucket, ERROR, [Loop-invariant call to int Hoist.foo(int,int) at line 57]
codetoanalyze/java/hoisting/Hoist.java, Hoist.void_hoist(int):void, 2, INVARIANT_CALL, no_bucket, ERROR, [Loop-invariant call to void Hoist.dumb_foo() at line 183]

Loading…
Cancel
Save