Skip to content

Commit

Permalink
[topl] A test for comparing arguments.
Browse files Browse the repository at this point in the history
Summary:
This is the kind of property for which the previous syntax forced one to
use spurious registers.

Reviewed By: ngorogiannis

Differential Revision: D20118863

fbshipit-source-id: b49740d33
  • Loading branch information
rgrig authored and facebook-github-bot committed Mar 4, 2020
1 parent 14aee52 commit 0fc2769
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion infer/tests/codetoanalyze/java/topl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

TESTS_DIR = ../../..

SUBDIRS = baos hasnext skip servlet
SUBDIRS = baos compareArgs hasnext skip servlet

test-%:
$(MAKE) -C $* test
Expand Down
30 changes: 30 additions & 0 deletions infer/tests/codetoanalyze/java/topl/compareArgs/CompareArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 CompareArgs {
static int max(int[] a, int i, int k) {
int m = a[i];
for (int j = i + 1; j < k; ++j) {
m = Math.max(m, a[j]);
}
return m;
}

static void aBad() {
int[] a = new int[10];
int x = max(a, 2, 2);
}

static void bOk() {
int[] a = new int[10];
int x = max(a, 2, 3);
}

static void cBad() {
int[] a = new int[10];
int x = max(a, 2, 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
property MaxArgs
nondet (start)
start -> start: *
start -> error: "CompareArgs.max"(Ignore, I, J, IgnoreRet) when I >= J
13 changes: 13 additions & 0 deletions infer/tests/codetoanalyze/java/topl/compareArgs/Makefile
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 4000 --topl-properties CompareArgs.topl --biabduction-only
INFERPRINT_OPTIONS = --issues-tests

SOURCES = $(wildcard *.java)

include $(TESTS_DIR)/javac.make
2 changes: 2 additions & 0 deletions infer/tests/codetoanalyze/java/topl/compareArgs/issues.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
codetoanalyze/java/topl/compareArgs/CompareArgs.java, CompareArgs.aBad():void, 0, TOPL_ERROR, no_bucket, ERROR, []
codetoanalyze/java/topl/compareArgs/CompareArgs.java, CompareArgs.cBad():void, 0, TOPL_ERROR, no_bucket, ERROR, []

0 comments on commit 0fc2769

Please sign in to comment.