From b54307f5d0888ec1a761a077775692a2a263d51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Sat, 29 Sep 2018 05:23:23 -0700 Subject: [PATCH] [Hoisting] Add test for FP due to no purity check Reviewed By: ngorogiannis Differential Revision: D10105786 fbshipit-source-id: 0a8dc9b73 --- .../java/hoisting/HoistIndirect.java | 33 +++++++++++++++++++ .../codetoanalyze/java/hoisting/issues.exp | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 infer/tests/codetoanalyze/java/hoisting/HoistIndirect.java diff --git a/infer/tests/codetoanalyze/java/hoisting/HoistIndirect.java b/infer/tests/codetoanalyze/java/hoisting/HoistIndirect.java new file mode 100644 index 000000000..7e7be9768 --- /dev/null +++ b/infer/tests/codetoanalyze/java/hoisting/HoistIndirect.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +class HoistIndirect { + + class Test { + + int a = 0; + + void set_test(Test test) { + test.a = 5; + } + + int get_test(Test test) { + return test.a; + } + + int indirect_modification_dont_hoist_FP(int size) { + int d = 0; + Test t = new Test(); + + for (int i = 0; i < size; i++) { + set_test(t); + d = get_test(t); // don't hoist since t changes + } + return d; + } + } +} diff --git a/infer/tests/codetoanalyze/java/hoisting/issues.exp b/infer/tests/codetoanalyze/java/hoisting/issues.exp index f95d2f924..15841cb5e 100644 --- a/infer/tests/codetoanalyze/java/hoisting/issues.exp +++ b/infer/tests/codetoanalyze/java/hoisting/issues.exp @@ -8,3 +8,5 @@ codetoanalyze/java/hoisting/Hoist.java, Hoist.two_function_call_hoist(int):void, 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] +codetoanalyze/java/hoisting/HoistIndirect.java, HoistIndirect$Test.indirect_modification_dont_hoist_FP(int):int, 5, INVARIANT_CALL, no_bucket, ERROR, [Loop-invariant call to void HoistIndirect$Test.set_test(HoistIndirect$Test) at line 27] +codetoanalyze/java/hoisting/HoistIndirect.java, HoistIndirect$Test.indirect_modification_dont_hoist_FP(int):int, 6, INVARIANT_CALL, no_bucket, ERROR, [Loop-invariant call to int HoistIndirect$Test.get_test(HoistIndirect$Test) at line 28]