Skip to content

Commit 8615e3b

Browse files
author
Thomas Kiley
authored
Merge pull request #3992 from thk123/clone-reference-array
Clone reference array
2 parents 054ac09 + 1e0d861 commit 8615e3b

12 files changed

+176
-1
lines changed
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
public class ArrayClone {
2+
public static void cloneReferenceArray() {
3+
ArrayClone[] a = {new ArrayClone(), new ArrayClone() };
4+
ArrayClone[] clone = a.clone();
5+
6+
assert(a.length == clone.length);
7+
assert(a[0] == clone[0]);
8+
assert(a[1] == clone[1]);
9+
assert(a != clone);
10+
}
11+
12+
public static void cloneObjectArray() {
13+
Object[] a = {new Object(), new Object() };
14+
Object[] clone = a.clone();
15+
16+
assert(a.length == clone.length);
17+
assert(a[0] == clone[0]);
18+
assert(a[1] == clone[1]);
19+
assert(a != clone);
20+
}
21+
22+
public static void cloneByteArray() {
23+
byte[] a = {(byte) 1, (byte) 2};
24+
byte[] clone = a.clone();
25+
26+
assert(a.length == clone.length);
27+
assert(a[0] == clone[0]);
28+
assert(a[1] == clone[1]);
29+
assert(a != clone);
30+
}
31+
32+
public static void cloneShortArray() {
33+
short[] a = {(short) 1, (short) 2};
34+
short[] clone = a.clone();
35+
36+
assert(a.length == clone.length);
37+
assert(a[0] == clone[0]);
38+
assert(a[1] == clone[1]);
39+
assert(a != clone);
40+
}
41+
42+
public static void cloneIntArray() {
43+
int[] a = {1, 2};
44+
int[] clone = a.clone();
45+
46+
assert(a.length == clone.length);
47+
assert(a[0] == clone[0]);
48+
assert(a[1] == clone[1]);
49+
assert(a != clone);
50+
}
51+
52+
public static void cloneLongArray() {
53+
long[] a = {1L, 2L };
54+
long[] clone = a.clone();
55+
56+
assert(a.length == clone.length);
57+
assert(a[0] == clone[0]);
58+
assert(a[1] == clone[1]);
59+
assert(a != clone);
60+
}
61+
62+
public static void cloneFloatArray() {
63+
float[] a = {1.0f, 2.0f};
64+
float[] clone = a.clone();
65+
66+
assert(a.length == clone.length);
67+
assert(a[0] == clone[0]);
68+
assert(a[1] == clone[1]);
69+
assert(a != clone);
70+
}
71+
72+
public static void cloneDoubleArray() {
73+
double[] a = {1.0, 2.0};
74+
double[] clone = a.clone();
75+
76+
assert(a.length == clone.length);
77+
assert(a[0] == clone[0]);
78+
assert(a[1] == clone[1]);
79+
assert(a != clone);
80+
}
81+
82+
public static void cloneBooleanArray() {
83+
boolean[] a = {true, false};
84+
boolean[] clone = a.clone();
85+
86+
assert(a.length == clone.length);
87+
assert(a[0] == clone[0]);
88+
assert(a[1] == clone[1]);
89+
assert(a != clone);
90+
}
91+
92+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneBooleanArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that the clone works on a boolean array
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneByteArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for byte arrays
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneDoubleArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for double arrays
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneFloatArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for float arrays
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneIntArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for int arrays
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneLongArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for long arrays
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneObjectArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for arrays of objects
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneReferenceArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for reference (non-object) arrays
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayClone.class
3+
--function ArrayClone.cloneShortArray
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Verify that clone works correctly for short arrays

jbmc/src/java_bytecode/ci_lazy_methods_needed.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ void ci_lazy_methods_neededt::gather_field_types(
138138
{
139139
const typet &element_type =
140140
java_array_element_type(to_struct_tag_type(class_type));
141-
if(element_type.id() == ID_pointer)
141+
if(
142+
element_type.id() == ID_pointer &&
143+
element_type.subtype().id() != ID_empty)
142144
{
143145
// This is a reference array -- mark its element type available.
144146
add_all_needed_classes(to_pointer_type(element_type));

0 commit comments

Comments
 (0)