forked from facebook/infer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[topl] Added tests for inefficient iteration
Summary: The test shows what that TOPL can express, in addition to bugs, efficiency properties. However, there seems to be an underlying problem in biabdaction that prevents this particular problem from being caught. Reviewed By: ngorogiannis Differential Revision: D20005404 fbshipit-source-id: 466f79050
- Loading branch information
1 parent
3538cae
commit 2888a90
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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. | ||
|
||
TESTS_DIR = ../../../.. | ||
|
||
INFER_OPTIONS = --seconds-per-iteration 10 --symops-per-iteration 20000 --topl-properties slowIter.topl --biabduction-only | ||
INFERPRINT_OPTIONS = --issues-tests | ||
|
||
SOURCES = $(wildcard *.java) | ||
|
||
include $(TESTS_DIR)/javac.make |
34 changes: 34 additions & 0 deletions
34
infer/tests/codetoanalyze/java/topl/slowIter/SlowIterTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import java.util.Map; | ||
|
||
class SlowIterTests { | ||
// T62611635 | ||
static <K, V> void FN_aBad(Map<K, V> m) { | ||
for (K k : m.keySet()) { | ||
System.out.printf("%s -> %s\n", k, m.get(k)); | ||
} | ||
} | ||
|
||
static <K, V> void aOk(Map<K, V> m) { | ||
for (Map.Entry<K, V> e : m.entrySet()) { | ||
System.out.printf("%s -> %s\n", e.getKey(), e.getValue()); | ||
} | ||
} | ||
|
||
// Inter-procedural variant of aBad. | ||
static <K, V> void FN_bBad(Map<K, V> m) { | ||
for (K k : m.keySet()) { | ||
print(k, m); | ||
} | ||
} | ||
|
||
static <K, V> void print(K k, Map<K, V> m) { | ||
System.out.printf("%s -> %s\n", k, m.get(k)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
property ShouldUseEntries | ||
nondet (start iteratingKeys) | ||
start -> start: * | ||
start -> gotKeys: S = "Map.keySet"(M) | ||
gotKeys -> iteratingKeys: I = "Set.iterator"(s) | ||
iteratingKeys -> iteratingKeys: * | ||
iteratingKeys -> gotOneKey: K = "Iterator.next"(i) | ||
gotOneKey -> error: ".*Map.get"(m, k) |