From 639c91c29fd30e18f5a6cdd43d5db82e297fecbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Thu, 23 May 2019 01:31:30 -0700 Subject: [PATCH] [loop-invariance] Add FPs for modified global and static invalidation Reviewed By: mbouaziz, ngorogiannis Differential Revision: D15451632 fbshipit-source-id: 67f5f4c89 --- .../java/hoisting/HoistGlobal.java | 59 +++++++++++++++++++ .../codetoanalyze/java/hoisting/issues.exp | 7 ++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/infer/tests/codetoanalyze/java/hoisting/HoistGlobal.java b/infer/tests/codetoanalyze/java/hoisting/HoistGlobal.java index 020cbbecb..284589d64 100644 --- a/infer/tests/codetoanalyze/java/hoisting/HoistGlobal.java +++ b/infer/tests/codetoanalyze/java/hoisting/HoistGlobal.java @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Set; class HoistGlobal { @@ -59,4 +61,61 @@ class HoistGlobal { global_modification_dont_hoist(size); } } + + private void processModulesDirectory_dont_hoist_FP( + Set modulesToDelete, String[] existingFiles) { + final AppModuleFileInfo fInfo = new AppModuleFileInfo(); + for (String existingFile : existingFiles) { + fInfo.setFileName(existingFile); + final boolean delete = modulesToDelete.contains(fInfo.mModuleName); + } + } + + private void processModulesDirectory_param_dont_hoist_FP( + Set modulesToDelete, + String[] existingFiles, + AppModuleFileInfo fInfo, + AppModuleFileInfo fInfo2) { + for (String existingFile : existingFiles) { + fInfo.setFileName(existingFile); + + final boolean delete = modulesToDelete.contains(fInfo2.mModuleName); + } + } + + private void processModulesDirectory_hoist(Set modulesToDelete, String[] existingFiles) { + final AppModuleFileInfo fInfo = new AppModuleFileInfo(); + for (String existingFile : existingFiles) { + fInfo.setFileName(existingFile); + final boolean delete = modulesToDelete.contains(fInfo.x); + } + } + + void remove_first_dont_hoist_FP(LinkedList list) { + + while (list.size() >= 10) { + list.removeFirst(); + } + } + + String get_first_hoist(LinkedList list, String s) { + + for (int i = 0; i <= 10; i++) { + String first = list.getFirst(); + if (list.contains(s)) { // hoist + return first; + } + } + return ""; + } +} + +class AppModuleFileInfo { + + static String mModuleName; + static Integer x; + + void setFileName(String fileName) { + mModuleName = fileName; + } } diff --git a/infer/tests/codetoanalyze/java/hoisting/issues.exp b/infer/tests/codetoanalyze/java/hoisting/issues.exp index 61e420b6f..3e122a77e 100644 --- a/infer/tests/codetoanalyze/java/hoisting/issues.exp +++ b/infer/tests/codetoanalyze/java/hoisting/issues.exp @@ -29,8 +29,13 @@ codetoanalyze/java/hoisting/Hoist.java, Hoist.void_hoist(int):void, 2, INVARIANT codetoanalyze/java/hoisting/Hoist.java, Hoist.x_not_invariant_dont_hoist(int,int,int):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void Hoist.x_not_invariant_dont_hoist(int,int,int)] codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal$Foo.read_global():int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int HoistGlobal$Foo.read_global()] codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal$Foo.return_zero():int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int HoistGlobal$Foo.return_zero()] -codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.global_modification_hoist_FN(java.util.ArrayList):int, 3, INVARIANT_CALL, no_bucket, ERROR, [The call to int ArrayList.size() at line 49 is loop-invariant] +codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.get_first_hoist(java.util.LinkedList,java.lang.String):java.lang.String, 4, INVARIANT_CALL, no_bucket, ERROR, [The call to boolean LinkedList.contains(Object) at line 105 is loop-invariant] +codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.global_modification_hoist_FN(java.util.ArrayList):int, 3, INVARIANT_CALL, no_bucket, ERROR, [The call to int ArrayList.size() at line 51 is loop-invariant] +codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.processModulesDirectory_dont_hoist_FP(java.util.Set,java.lang.String[]):void, 5, INVARIANT_CALL, no_bucket, ERROR, [The call to boolean Set.contains(Object) at line 70 is loop-invariant] +codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.processModulesDirectory_hoist(java.util.Set,java.lang.String[]):void, 4, INVARIANT_CALL, no_bucket, ERROR, [The call to boolean Set.contains(Object) at line 90 is loop-invariant] +codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.processModulesDirectory_param_dont_hoist_FP(java.util.Set,java.lang.String[],AppModuleFileInfo,AppModuleFileInfo):void, 8, INVARIANT_CALL, no_bucket, ERROR, [The call to boolean Set.contains(Object) at line 82 is loop-invariant] codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.read_global():int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int HoistGlobal.read_global()] +codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.remove_first_dont_hoist_FP(java.util.LinkedList):void, 2, INVARIANT_CALL, no_bucket, ERROR, [The call to int LinkedList.size() at line 96 is loop-invariant] codetoanalyze/java/hoisting/HoistGlobal.java, HoistGlobal.return_one():int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int HoistGlobal.return_one()] codetoanalyze/java/hoisting/HoistIndirect.java, HoistIndirect$Test.deep_modification_dont_hoist(int):int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int HoistIndirect$Test.deep_modification_dont_hoist(int)] codetoanalyze/java/hoisting/HoistIndirect.java, HoistIndirect$Test.foo(int):int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int HoistIndirect$Test.foo(int)]