|
|
|
(*
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*)
|
|
|
|
|
|
|
|
open! IStd
|
|
|
|
|
|
|
|
(** module for running OCaml unit tests *)
|
|
|
|
|
|
|
|
let rec mk_test_fork_proof test =
|
|
|
|
let open OUnitTest in
|
|
|
|
match test with
|
|
|
|
| TestCase (length, f) ->
|
|
|
|
TestCase (length, ForkUtils.protect ~f)
|
|
|
|
| TestList l ->
|
|
|
|
TestList (List.map ~f:mk_test_fork_proof l)
|
|
|
|
| TestLabel (label, test) ->
|
|
|
|
TestLabel (label, mk_test_fork_proof test)
|
|
|
|
|
|
|
|
|
|
|
|
let () =
|
|
|
|
ResultsDir.create_results_dir () ;
|
|
|
|
let open OUnit2 in
|
|
|
|
let tests =
|
|
|
|
(* OUnit runs tests in parallel using fork(2) *)
|
|
|
|
List.map ~f:mk_test_fork_proof
|
|
|
|
( [ AbstractInterpreterTests.tests
|
|
|
|
; AccessTreeTests.tests
|
|
|
|
; AddressTakenTests.tests
|
|
|
|
; CStubsTests.tests
|
|
|
|
; DifferentialFiltersTests.tests
|
|
|
|
; DifferentialTests.tests
|
|
|
|
; FileDiffTests.tests
|
|
|
|
; GradleTests.tests
|
Fix SIL to HIL conversion for Exp.Var inside Lfield and Lindex (#1372)
Summary:
When accessing a field or array offset of a pure variable (`Exp.Var`) that does not resolve to an access expression, `HilExp.of_sil` will create an extraneous dereference that causes `HilExp.get_typ` to fail. This pull request wraps variables that are the bases of Lfield or Lindex expressions with AddressOf before they're dereferenced (this is already done for Lvar inside `AccessExpression.of_pvar`) and adds a couple of unit tests that make sure it behaves as expected.
**More details on the bug:**
Given the following code:
```
if (!event_obj->dict)
```
and SIL:
```
n$6=_fun_gdb::ref_ptr<event_object,gdbpy_ref_policy<event_object>>::operator->(&event_obj:gdb::ref_ptr<event_object,gdbpy_ref_policy<event_object>>&) [line 38, column 8];
n$7=*n$6.dict:_object* [line 38, column 8];
PRUNE(!n$7, true); [line 38, column 8];
```
`operator->` has return type `event_object*`, but `n$6.dict` only has access to the type of the struct, `event_object`. `of_sil` [calls](https://github.com/facebook/infer/blob/9f98368e49d411941bb8e2a1e1839bed18cd625e/infer/src/absint/HilExp.ml#L567) `access_expr_of_lhs_exp` with that type, which [calls](https://github.com/facebook/infer/blob/9f98368e49d411941bb8e2a1e1839bed18cd625e/infer/src/absint/HilExp.ml#L498) `access_exprs_of_exp` (note that `add_deref` is always true). The Lfield case will then [recurse](https://github.com/facebook/infer/blob/9f98368e49d411941bb8e2a1e1839bed18cd625e/infer/src/absint/HilExp.ml#L469) to process the Exp.Var, and `AccessExpression.of_id` will return an `AccessPath.base` that is then [dereferenced](https://github.com/facebook/infer/blob/9f98368e49d411941bb8e2a1e1839bed18cd625e/infer/src/absint/HilExp.ml#L440). When resolving types, `get_typ` will find a non-pointer type wrapped by a `Dereference` and return [None](https://github.com/facebook/infer/blob/9f98368e49d411941bb8e2a1e1839bed18cd625e/infer/src/absint/HilExp.ml#L286). To fix this, we match what [of_pvar](https://github.com/facebook/infer/blob/9f98368e49d411941bb8e2a1e1839bed18cd625e/infer/src/absint/HilExp.ml#L295) does and wrap the base in an AddressOf, which is removed by the dereference.
Pull Request resolved: https://github.com/facebook/infer/pull/1372
Reviewed By: ngorogiannis
Differential Revision: D25803049
Pulled By: jvillard
fbshipit-source-id: ceadc8cad
4 years ago
|
|
|
; HilExpTests.tests
|
|
|
|
; IListTests.tests
|
|
|
|
; JavaClassNameTests.tests
|
|
|
|
; JavaProfilerSamplesTest.tests
|
|
|
|
; LivenessTests.tests
|
|
|
|
; LRUHashtblTests.tests
|
|
|
|
; ProcCfgTests.tests
|
|
|
|
; RestartSchedulerTests.tests
|
|
|
|
; SchedulerTests.tests
|
|
|
|
; SeverityTests.tests
|
|
|
|
; TaintTests.tests
|
|
|
|
; TraceTests.tests
|
|
|
|
; WeakTopologicalOrderTests.tests ]
|
|
|
|
@ ClangTests.tests @ AllNullsafeTests.tests )
|
|
|
|
in
|
|
|
|
let test_suite = "all" >::: tests in
|
|
|
|
OUnit2.run_test_tt_main test_suite
|