@ -12,7 +12,7 @@ module TestInterpreter =
let tests =
let tests =
let open OUnit2 in
let open OUnit2 in
let open AnalyzerTester . StructuredSil in
let open AnalyzerTester . StructuredSil in
let assert_empty = invariant " { }" in
let assert_empty = invariant " normal:{ }, exn: { }" in
let fun_ptr_typ = Typ . mk ( Tptr ( Typ . mk Tfun , Pk_pointer ) ) in
let fun_ptr_typ = Typ . mk ( Tptr ( Typ . mk Tfun , Pk_pointer ) ) in
let closure_exp captured_pvars =
let closure_exp captured_pvars =
let mk_captured_var str =
let mk_captured_var str =
@ -27,80 +27,95 @@ let tests =
Exp . zero
Exp . zero
in
in
let test_list =
let test_list =
[ ( " basic_live " , [ invariant " { b }" ; id_assign_var " a " " b " ] )
[ ( " basic_live " , [ invariant " normal: { b }, exn:{ }" ; id_assign_var " a " " b " ] )
; ( " basic_live_then_dead "
; ( " basic_live_then_dead "
, [ assert_empty ; var_assign_int " b " 1 ; invariant " { b } " ; id_assign_var " a " " b " ] )
, [ assert_empty
; var_assign_int " b " 1
; invariant " normal:{ b }, exn:{ } "
; id_assign_var " a " " b " ] )
; ( " iterative_live "
; ( " iterative_live "
, [ invariant " { b, f, d } "
, [ invariant " normal: { b, f, d }, exn:{ }"
; id_assign_var " e " " f "
; id_assign_var " e " " f "
; invariant " { b, d }"
; invariant " normal: { b, d }, exn:{ }"
; id_assign_var " c " " d "
; id_assign_var " c " " d "
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] )
; id_assign_var " a " " b " ] )
; ( " live_kill_live "
; ( " live_kill_live "
, [ invariant " { b }"
, [ invariant " normal: { b }, exn:{ }"
; id_assign_var " c " " b "
; id_assign_var " c " " b "
; assert_empty
; assert_empty
; var_assign_int " b " 1
; var_assign_int " b " 1
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] )
; id_assign_var " a " " b " ] )
; ( " basic_live_load " , [ invariant " { y$0 }" ; id_assign_id " x " " y " ] )
; ( " basic_live_load " , [ invariant " normal: { y$0 }, exn:{ }" ; id_assign_id " x " " y " ] )
; ( " basic_live_then_kill_load "
; ( " basic_live_then_kill_load "
, [ invariant " { z$0 } " ; id_assign_id " y " " z " ; invariant " { y$0 } " ; id_assign_id " x " " y " ] )
, [ invariant " normal:{ z$0 }, exn:{ } "
; id_assign_id " y " " z "
; invariant " normal:{ y$0 }, exn:{ } "
; id_assign_id " x " " y " ] )
; ( " set_id "
; ( " set_id "
, (* this is * x = y, which is a read of both x and y *)
, (* this is * x = y, which is a read of both x and y *)
[ invariant " { x$0, y$0 } " ; id_set_id " x " " y " ] )
[ invariant " normal: { x$0, y$0 }, exn:{ }" ; id_set_id " x " " y " ] )
; ( " if_exp_live "
; ( " if_exp_live "
, [ assert_empty ; var_assign_int " x " 1 ; invariant " { x } " ; If ( var_of_str " x " , [] , [] ) ] )
, [ assert_empty
; var_assign_int " x " 1
; invariant " normal:{ x }, exn:{ } "
; If ( var_of_str " x " , [] , [] ) ] )
; ( " while_exp_live "
; ( " while_exp_live "
, [ assert_empty ; var_assign_int " x " 1 ; invariant " { x } " ; While ( var_of_str " x " , [] ) ] )
, [ assert_empty
; ( " call_params_live " , [ invariant " { b, a, c } " ; call_unknown [ " a " ; " b " ; " c " ] ] )
; var_assign_int " x " 1
; invariant " normal:{ x }, exn:{ } "
; While ( var_of_str " x " , [] ) ] )
; ( " call_params_live " , [ invariant " normal:{ b, a, c }, exn:{ } " ; call_unknown [ " a " ; " b " ; " c " ] ] )
; ( " dead_after_call_with_retval "
; ( " dead_after_call_with_retval "
, [ assert_empty
, [ assert_empty
; call_unknown ~ return : ( " y " , Typ . mk ( Tint IInt ) ) []
; call_unknown ~ return : ( " y " , Typ . mk ( Tint IInt ) ) []
; invariant " { y$0 }"
; invariant " normal: { y$0 }, exn:{ }"
; id_assign_id " x " " y " ] )
; id_assign_id " x " " y " ] )
; ( " closure_captured_live "
; ( " closure_captured_live "
, [ invariant " { b$0, c$0 } " ; var_assign_exp ~ rhs_typ : fun_ptr_typ " a " ( closure_exp [ " b " ; " c " ] ) ]
, [ invariant " normal:{ b$0, c$0 }, exn:{ } "
)
; var_assign_exp ~ rhs_typ : fun_ptr_typ " a " ( closure_exp [ " b " ; " c " ] ) ] )
; ( " if_conservative_live1 " , [ invariant " { b } " ; If ( unknown_cond , [ id_assign_var " a " " b " ] , [] ) ] )
; ( " if_conservative_live1 "
, [ invariant " normal:{ b }, exn:{ } " ; If ( unknown_cond , [ id_assign_var " a " " b " ] , [] ) ] )
; ( " if_conservative_live2 "
; ( " if_conservative_live2 "
, [ invariant " { b, d } " ; If ( unknown_cond , [ id_assign_var " a " " b " ] , [ id_assign_var " c " " d " ] ) ]
, [ invariant " normal:{ b, d }, exn:{ } "
)
; If ( unknown_cond , [ id_assign_var " a " " b " ] , [ id_assign_var " c " " d " ] ) ] )
; ( " if_conservative_kill "
; ( " if_conservative_kill "
, [ invariant " { b }"
, [ invariant " normal: { b }, exn:{ }"
; If ( unknown_cond , [ var_assign_int " b " 1 ] , [] )
; If ( unknown_cond , [ var_assign_int " b " 1 ] , [] )
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] )
; id_assign_var " a " " b " ] )
; ( " if_conservative_kill_live "
; ( " if_conservative_kill_live "
, [ invariant " { b, d }"
, [ invariant " normal: { b, d }, exn:{ }"
; If ( unknown_cond , [ var_assign_int " b " 1 ] , [ id_assign_var " c " " d " ] )
; If ( unknown_cond , [ var_assign_int " b " 1 ] , [ id_assign_var " c " " d " ] )
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] )
; id_assign_var " a " " b " ] )
; ( " if_precise1 "
; ( " if_precise1 "
, [ assert_empty
, [ assert_empty
; If
; If
( unknown_cond
( unknown_cond
, [ var_assign_int " b " 1 ; invariant " { b } " ; id_assign_var " a " " b " ]
, [ var_assign_int " b " 1 ; invariant " normal:{ b }, exn:{ } " ; id_assign_var " a " " b " ]
, [ var_assign_int " d " 1 ; invariant " { d } " ; id_assign_var " c " " d " ] ) ] )
, [ var_assign_int " d " 1 ; invariant " normal:{ d }, exn:{ } " ; id_assign_var " c " " d " ] ) ]
)
; ( " if_precise2 "
; ( " if_precise2 "
, [ assert_empty
, [ assert_empty
; If ( unknown_cond , [ var_assign_int " b " 2 ] , [ var_assign_int " b " 1 ] )
; If ( unknown_cond , [ var_assign_int " b " 2 ] , [ var_assign_int " b " 1 ] )
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] )
; id_assign_var " a " " b " ] )
; ( " loop_as_if1 " , [ invariant " { b } " ; While ( unknown_cond , [ id_assign_var " a " " b " ] ) ] )
; ( " loop_as_if1 "
, [ invariant " normal:{ b }, exn:{ } " ; While ( unknown_cond , [ id_assign_var " a " " b " ] ) ] )
; ( " loop_as_if2 "
; ( " loop_as_if2 "
, [ invariant " { b }"
, [ invariant " normal: { b }, exn:{ }"
; While ( unknown_cond , [ var_assign_int " b " 1 ] )
; While ( unknown_cond , [ var_assign_int " b " 1 ] )
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] )
; id_assign_var " a " " b " ] )
; ( " loop_before_after "
; ( " loop_before_after "
, [ invariant " { b, d }"
, [ invariant " normal: { b, d }, exn:{ }"
; While ( unknown_cond , [ id_assign_var " b " " d " ] )
; While ( unknown_cond , [ id_assign_var " b " " d " ] )
; invariant " { b }"
; invariant " normal: { b }, exn:{ }"
; id_assign_var " a " " b " ] ) ]
; id_assign_var " a " " b " ] ) ]
| > TestInterpreter . create_tests
| > TestInterpreter . create_tests
( fun summary -> Summary . get_proc_desc summary )
( fun summary -> Summary . get_proc_desc summary )
~ initial : Liveness . Domain . empty
~ initial : Liveness . Domain . bottom
in
in
" liveness_test_suite " > :: : test_list
" liveness_test_suite " > :: : test_list