Summary: Now one can use the pattern #ArrayWrite(A,I) to match on a write at index I in array A. This only works in the Pulse variant of Topl (not in the one based on SIL instrumentation). Reviewed By: jvillard Differential Revision: D25202768 fbshipit-source-id: 479f434e3master
parent
33071b82b5
commit
59daa1f022
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
class ImmutableArray {
|
||||||
|
|
||||||
|
final int[] testArray = new int[] {0, 1, 2, 4};
|
||||||
|
|
||||||
|
int[] getTestArray() {
|
||||||
|
return testArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
void badA() {
|
||||||
|
int[] array = getTestArray();
|
||||||
|
array[2] = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
void badB() {
|
||||||
|
int[] array = getTestArray();
|
||||||
|
int[] otherArray = array;
|
||||||
|
otherArray[2] = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
void badC() {
|
||||||
|
int[] array = getTestArray();
|
||||||
|
otherMutateArray(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
void badABC() {
|
||||||
|
int[] array = getTestArray();
|
||||||
|
array[2] = 7;
|
||||||
|
int[] otherArray = array;
|
||||||
|
otherArray[2] = 7;
|
||||||
|
otherMutateArray(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
void otherMutateArray(int[] array) {
|
||||||
|
array[2] = 7;
|
||||||
|
}
|
||||||
|
}
|
@ -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 = --topl-properties immutableArray.topl --pulse-only
|
||||||
|
INFERPRINT_OPTIONS = --issues-tests
|
||||||
|
|
||||||
|
SOURCES = $(wildcard *.java)
|
||||||
|
|
||||||
|
include $(TESTS_DIR)/javac.make
|
@ -0,0 +1,7 @@
|
|||||||
|
property ImmutableArrayModified
|
||||||
|
prefix "ImmutableArray"
|
||||||
|
nondet (start)
|
||||||
|
start -> start: *
|
||||||
|
start -> tracking: getTestArray(IgnoreObject, Array) => a := Array
|
||||||
|
tracking -> error: #ArrayWrite(Array, IgnoreIndex) when a == Array
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
codetoanalyze/java/topl/immutableArray/ImmutableArray.java, ImmutableArray.badA():void, 0, TOPL_PULSE_ERROR, no_bucket, ERROR, [call to int[] ImmutableArray.getTestArray(),call to int[] ImmutableArray.getTestArray(),write to array]
|
||||||
|
codetoanalyze/java/topl/immutableArray/ImmutableArray.java, ImmutableArray.badABC():void, 0, TOPL_PULSE_ERROR, no_bucket, ERROR, [call to int[] ImmutableArray.getTestArray(),call to int[] ImmutableArray.getTestArray(),write to array,call to void ImmutableArray.otherMutateArray(int[])]
|
||||||
|
codetoanalyze/java/topl/immutableArray/ImmutableArray.java, ImmutableArray.badB():void, 0, TOPL_PULSE_ERROR, no_bucket, ERROR, [call to int[] ImmutableArray.getTestArray(),call to int[] ImmutableArray.getTestArray(),write to array]
|
||||||
|
codetoanalyze/java/topl/immutableArray/ImmutableArray.java, ImmutableArray.badC():void, 0, TOPL_PULSE_ERROR, no_bucket, ERROR, [call to int[] ImmutableArray.getTestArray(),call to int[] ImmutableArray.getTestArray(),call to void ImmutableArray.otherMutateArray(int[]),write to array]
|
Loading…
Reference in new issue