Skip to content

Commit 12bce17

Browse files
authored
Merge pull request #3826 from smowton/smowton/fix/json-expr-simplify-pointers
Fix json_expr simplification of pointers
2 parents 8984eb9 + d141953 commit 12bce17

File tree

12 files changed

+117
-20
lines changed

12 files changed

+117
-20
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ jobs:
9696
- g++-5
9797
- libubsan0
9898
- parallel
99+
- jq
99100
before_install:
100101
- mkdir bin
101102
- ln -s /usr/bin/gcc-5 bin/gcc
@@ -130,6 +131,7 @@ jobs:
130131
- libwww-perl
131132
- g++-5
132133
- libubsan0
134+
- jq
133135
before_install:
134136
- mkdir bin
135137
- ln -s /usr/bin/gcc-5 bin/gcc
@@ -158,6 +160,7 @@ jobs:
158160
- libstdc++-5-dev
159161
- libubsan0
160162
- parallel
163+
- jq
161164
before_install:
162165
- mkdir bin
163166
- ln -s /usr/bin/gcc-5 bin/gcc
@@ -186,6 +189,7 @@ jobs:
186189
- clang-7
187190
- libstdc++-5-dev
188191
- libubsan0
192+
- jq
189193
before_install:
190194
- mkdir bin
191195
- ln -s /usr/bin/gcc-5 bin/gcc
@@ -212,6 +216,7 @@ jobs:
212216
- ubuntu-toolchain-r-test
213217
packages:
214218
- g++-5
219+
- jq
215220
before_install:
216221
- mkdir bin
217222
- ln -s /usr/bin/gcc-5 bin/gcc
@@ -238,6 +243,7 @@ jobs:
238243
- ubuntu-toolchain-r-test
239244
packages:
240245
- g++-7
246+
- jq
241247
before_install:
242248
- mkdir bin
243249
- ln -s /usr/bin/gcc-7 bin/gcc
@@ -270,6 +276,7 @@ jobs:
270276
- libstdc++-5-dev
271277
- libubsan0
272278
- parallel
279+
- jq
273280
before_install:
274281
- mkdir bin
275282
# Use gcc/g++ 5 for tests, as Clang doesn't work yet

buildspec-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ phases:
44
install:
55
commands:
66
- choco install cyg-get -y --no-progress
7-
- cyg-get bash patch bison flex make wget perl
7+
- cyg-get bash patch bison flex make wget perl jq
88
- nuget install clcache -OutputDirectory "c:\tools" -ExcludeVersion -Version 4.1.0
99

1010
build:

buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ phases:
88
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA9EF27F
99
- add-apt-repository ppa:openjdk-r/ppa -y
1010
- apt-get update -y
11-
- apt-get install -y g++-5 flex bison make git libwww-perl patch ccache libc6-dev-i386
11+
- apt-get install -y g++-5 flex bison make git libwww-perl patch ccache libc6-dev-i386 jq
1212
- apt-get install -y openjdk-8-jdk
1313
- update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1
1414
- update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 1

jbmc/regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ add_subdirectory(janalyzer-taint)
1212
add_subdirectory(jbmc-concurrency)
1313
add_subdirectory(jbmc-inheritance)
1414
add_subdirectory(jbmc-generics)
15+
add_subdirectory(jbmc-json-ui)

jbmc/regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ DIRS = janalyzer \
66
jbmc \
77
jbmc-concurrency \
88
jbmc-inheritance \
9+
jbmc-json-ui \
910
jbmc-strings \
1011
jdiff \
1112
strings-smoke-tests \
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
find_program(JQ jq)
2+
if(NOT JQ)
3+
message("Skipping JBMC JSON-UI tests: couldn't find jq in your path")
4+
else()
5+
add_test_pl_tests(
6+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:jbmc>"
7+
)
8+
endif()
9+

jbmc/regression/jbmc-json-ui/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
default: tests.log
2+
3+
include ../../src/config.inc
4+
5+
test:
6+
ifeq (, $(shell which jq))
7+
echo "JBMC JSON-UI tests skipped (can't find 'jq' in your path)"
8+
else
9+
@../$(CPROVER_DIR)/regression/test.pl -p -c "../chain.sh ../../../src/jbmc/jbmc"
10+
endif
11+
12+
tests.log: ../$(CPROVER_DIR)/regression/test.pl test
13+
14+
show:
15+
@for dir in *; do \
16+
if [ -d "$$dir" ]; then \
17+
vim -o "$$dir/*.java" "$$dir/*.out"; \
18+
fi; \
19+
done;
20+
21+
clean:
22+
find -name '*.out' -execdir $(RM) '{}' \;
23+
find -name '*.gb' -execdir $(RM) '{}' \;
24+
$(RM) tests.log tests-symex-driven-loading.log
25+
26+
%.class: %.java ../../src/org.cprover.jar
27+
javac -g -cp ../../src/org.cprover.jar:. $<
28+
29+
nondet_java_files := $(shell find . -name "Nondet*.java")
30+
nondet_class_files := $(patsubst %.java, %.class, $(nondet_java_files))
31+
32+
.PHONY: nondet-class-files
33+
nondet-class-files: $(nondet_class_files)
34+
35+
.PHONY: clean-nondet-class-files
36+
clean-nondet-class-files:
37+
-rm $(nondet_class_files)

jbmc/regression/jbmc-json-ui/chain.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
JBMC_PATH=$1
4+
shift
5+
6+
JQ_COMMAND=$1
7+
shift
8+
9+
$JBMC_PATH "$@" | jq -c "$JQ_COMMAND"
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.class
3+
'.[] | select(has("result")) | .result | .[] | select(has("trace")) | .trace | .[] | select(has("value")) | .value | select(.name == "pointer") | {has_data: has("data")}' --json-ui --trace
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\{"has_data":true\}
7+
--
8+
\{"has_data":false\}
9+
--
10+
This checks that all pointer assignments in the test program have a "data" entry,
11+
which is given when json_expr can determine what object is referenced on the RHS
12+
(e.g. x = &dynamic_object1.@some_subclass yields "data": "dynamic_object1" in the trace)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class test {
2+
3+
public static void main(String[] args) {
4+
5+
test t = new test();
6+
test[] ts = new test[1];
7+
ts[0] = t;
8+
assert ts[0] == null;
9+
10+
}
11+
12+
}

src/goto-programs/json_expr.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Peter Schrammel
1414
#include <util/arith_tools.h>
1515
#include <util/config.h>
1616
#include <util/expr.h>
17+
#include <util/expr_util.h>
1718
#include <util/fixedbv.h>
1819
#include <util/identifier.h>
1920
#include <util/ieee_float.h>
@@ -46,27 +47,35 @@ static exprt simplify_json_expr(const exprt &src)
4647
}
4748
}
4849
}
49-
else if(
50-
src.id() == ID_address_of &&
51-
to_address_of_expr(src).object().id() == ID_member &&
52-
id2string(
53-
to_member_expr(to_address_of_expr(src).object()).get_component_name())
54-
.find("@") != std::string::npos)
50+
else if(src.id() == ID_typecast)
5551
{
56-
// simplify expressions of the form &member_expr(object, @class_identifier)
57-
return simplify_json_expr(to_address_of_expr(src).object());
52+
return simplify_json_expr(to_typecast_expr(src).op());
5853
}
59-
else if(
60-
src.id() == ID_address_of &&
61-
to_address_of_expr(src).object().id() == ID_index &&
62-
to_index_expr(to_address_of_expr(src).object()).index().id() ==
63-
ID_constant &&
64-
to_constant_expr(to_index_expr(to_address_of_expr(src).object()).index())
65-
.value_is_zero_string())
54+
else if(src.id() == ID_address_of)
6655
{
67-
// simplify expressions of the form &array[0]
68-
return simplify_json_expr(
69-
to_index_expr(to_address_of_expr(src).object()).array());
56+
const exprt &object = skip_typecast(to_address_of_expr(src).object());
57+
58+
if(object.id() == ID_symbol)
59+
{
60+
// simplify expressions of the form &symbol
61+
return simplify_json_expr(object);
62+
}
63+
else if(
64+
object.id() == ID_member &&
65+
id2string(to_member_expr(object).get_component_name()).find("@") !=
66+
std::string::npos)
67+
{
68+
// simplify expressions of the form &member(object, @class_identifier)
69+
return simplify_json_expr(object);
70+
}
71+
else if(
72+
object.id() == ID_index &&
73+
to_index_expr(object).index().id() == ID_constant &&
74+
to_constant_expr(to_index_expr(object).index()).value_is_zero_string())
75+
{
76+
// simplify expressions of the form &array[0]
77+
return simplify_json_expr(to_index_expr(object).array());
78+
}
7079
}
7180
else if(
7281
src.id() == ID_member &&

0 commit comments

Comments
 (0)