Skip to content

Commit 8f6dab8

Browse files
author
Thomas Kiley
authored
Merge pull request diffblue#2261 from thk123/bugfix/TG-3652/wrong-generic-type-two-params
Don't store generic values as comments [TG-3652]
2 parents 262affb + e1398bc commit 8f6dab8

17 files changed

+126
-5
lines changed

jbmc/regression/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ add_subdirectory(janalyzer-taint)
1111
add_subdirectory(jbmc-concurrency)
1212
add_subdirectory(jbmc-inheritance)
1313
add_subdirectory(jbmc-cover)
14+
add_subdirectory(jbmc-generics)

jbmc/regression/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ DIRS = janalzyer-taint \
99
jbmc-strings \
1010
jdiff \
1111
string-smoke-tests \
12+
jbmc-generics \
1213
# Empty last line
1314

1415
# Tests under goto-gcc cannot be run on Windows, so appveyor.yml unlinks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_test_pl_tests(
2+
"$<TARGET_FILE:jbmc>"
3+
)
4+
5+
add_test_pl_profile(
6+
"jbmc-symex-driven-lazy-loading"
7+
"$<TARGET_FILE:jbmc> --symex-driven-lazy-loading"
8+
"-C;-X;symex-driven-lazy-loading-expected-failure;-s;symex-driven-loading"
9+
"CORE"
10+
)
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
default: tests.log
2+
3+
include ../../src/config.inc
4+
5+
test:
6+
@../$(CPROVER_DIR)/regression/test.pl -p -c ../../../src/jbmc/jbmc
7+
@../$(CPROVER_DIR)/regression/test.pl -p -c "../../../src/jbmc/jbmc --symex-driven-lazy-loading" -X symex-driven-lazy-loading-expected-failure -s symex-driven-loading
8+
9+
tests.log: ../$(CPROVER_DIR)/regression/test.pl
10+
@../$(CPROVER_DIR)/regression/test.pl -p -c ../../../src/jbmc/jbmc
11+
@../$(CPROVER_DIR)/regression/test.pl -p -c "../../../src/jbmc/jbmc --symex-driven-lazy-loading" -X symex-driven-lazy-loading-expected-failure -s symex-driven-loading
12+
13+
show:
14+
@for dir in *; do \
15+
if [ -d "$$dir" ]; then \
16+
vim -o "$$dir/*.java" "$$dir/*.out"; \
17+
fi; \
18+
done;
19+
20+
clean:
21+
find -name '*.out' -execdir $(RM) '{}' \;
22+
find -name '*.gb' -execdir $(RM) '{}' \;
23+
$(RM) tests.log
24+
25+
%.class: %.java ../../src/org.cprover.jar
26+
javac -g -cp ../../src/org.cprover.jar:. $<
27+
28+
nondet_java_files := $(shell find . -name "Nondet*.java")
29+
nondet_class_files := $(patsubst %.java, %.class, $(nondet_java_files))
30+
31+
.PHONY: nondet-class-files
32+
nondet-class-files: $(nondet_class_files)
33+
34+
.PHONY: clean-nondet-class-files
35+
clean-nondet-class-files:
36+
-rm $(nondet_class_files)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Gen<T> {
2+
public T t;
3+
}
4+
5+
class IWrapper {
6+
public int i;
7+
}
8+
9+
class BWrapper {
10+
public boolean b;
11+
}
12+
13+
class TestClass {
14+
static void testFunction() {
15+
Gen<IWrapper> a = new Gen<>();
16+
Gen b = a;
17+
assert(b == a);
18+
Gen<BWrapper> c;
19+
c = b;
20+
assert(c == b);
21+
assert(c.equals(a));
22+
}
23+
24+
static void testFunctionWithInput(Gen a, Gen<IWrapper> b, Gen<BWrapper> c) {
25+
if(a != null && b != null && c != null &&
26+
a.t != null && b.t != null && c.t != null)
27+
{
28+
b = a;
29+
assert(b == a);
30+
a = c;
31+
assert(a == c);
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
TestClass.class
3+
--function TestClass.testFunction --classpath ../../../src/java_bytecode/library/core-models.jar:.
4+
EXIT=0
5+
SIGNAL=0
6+
VERIFICATION SUCCESSFUL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
TestClass.class
3+
--function TestClass.testFunctionWithInput
4+
EXIT=0
5+
SIGNAL=0
6+
VERIFICATION SUCCESSFUL
7+
--
8+
--
9+
Adding the core models causes a exception in convert_struct relating to the
10+
`monitorCount` component. See diffblue/cbmc#2307
Binary file not shown.

jbmc/unit/java_bytecode/goto_program_generics/GenericFields.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ public void foo() {
1111

1212
class MultipleGenericFields {
1313
Wrapper<IWrapper> field_input1;
14-
Wrapper<IWrapper> field_input2;
14+
Wrapper<BWrapper> field_input2;
1515
public void foo() {
1616
field_input1.field.i = 10;
17-
field_input2.field.i = 20;
17+
field_input2.field.b = true;
1818
}
1919
}
2020

jbmc/unit/java_bytecode/goto_program_generics/GenericHelper.java

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ public IWrapper(int ii) {
66
}
77
}
88

9+
// boolean wrapper
10+
class BWrapper {
11+
public boolean b;
12+
public BWrapper(boolean bb) {
13+
b = bb;
14+
}
15+
}
16+
917
// simple generic class
1018
class Wrapper<T> {
1119
public T field;

jbmc/unit/java_bytecode/goto_program_generics/generic_parameters_test.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ SCENARIO(
102102
require_goto_statements::require_entry_point_argument_assignment(
103103
"this", entry_point_code);
104104

105+
THEN("Type of multiple generic fields should be right")
106+
{
107+
const typet &class_type =
108+
symbol_table.lookup_ref("java::GenericFields$MultipleGenericFields")
109+
.type;
110+
111+
const auto &component = require_type::require_component(
112+
to_java_class_type(class_type), "field_input2");
113+
114+
const java_generic_typet &type =
115+
require_type::require_java_generic_type(component.type());
116+
require_type::require_pointer(
117+
type.generic_type_arguments()[0], symbol_typet{"java::BWrapper"});
118+
}
119+
105120
THEN("Object 'this' has field 'field_input1' of type Wrapper")
106121
{
107122
const auto &field_input1_name =
@@ -136,13 +151,13 @@ SCENARIO(
136151
{},
137152
entry_point_code);
138153

139-
THEN("Object 'field_input1' has field 'field' of type IWrapper")
154+
THEN("Object 'field_input2' has field 'field' of type BWrapper")
140155
{
141156
require_goto_statements::require_struct_component_assignment(
142157
field_input2_name,
143158
{},
144159
"field",
145-
"java::IWrapper",
160+
"java::BWrapper",
146161
{},
147162
entry_point_code);
148163
}

src/util/irep_ids.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ IREP_ID_TWO(C_java_implicitly_generic_class_type, #java_implicitly_generic_class
655655
IREP_ID_TWO(C_java_generic_symbol, #java_generic_symbol)
656656
IREP_ID_TWO(generic_types, #generic_types)
657657
IREP_ID_TWO(implicit_generic_types, #implicit_generic_types)
658-
IREP_ID_TWO(type_variables, #type_variables)
658+
IREP_ID_ONE(type_variables)
659659
IREP_ID_TWO(java_lambda_method_handle_index, lambda_method_handle_index)
660660
IREP_ID_TWO(java_lambda_method_handles, lambda_method_handles)
661661
IREP_ID_ONE(havoc_object)

0 commit comments

Comments
 (0)