Skip to content

Commit 9669534

Browse files
authored
Merge pull request #4481 from JohnDumbell/jd/enhancement/isx_double_cast
i2x cast back to int for byte, short and char
2 parents 1899067 + d9f8beb commit 9669534

File tree

9 files changed

+104
-0
lines changed

9 files changed

+104
-0
lines changed
Binary file not shown.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
public class IntToX {
2+
public void shortCast(int arg) {
3+
intMethod((byte)arg);
4+
assert true;
5+
}
6+
7+
public void byteCast(int arg) {
8+
intMethod((short)arg);
9+
assert true;
10+
}
11+
12+
public void charCast(int arg) {
13+
intMethod((char)arg);
14+
assert true;
15+
}
16+
17+
public void floatCast(int arg) {
18+
floatMethod((float)arg);
19+
assert true;
20+
}
21+
22+
public float floatMethod(float f) {
23+
return f;
24+
}
25+
26+
public void longCast(int arg) {
27+
longMethod((long)arg);
28+
assert true;
29+
}
30+
31+
public float longMethod(long f) {
32+
return f;
33+
}
34+
35+
public void doubleCast(int arg) {
36+
doubleMethod((double)arg);
37+
assert true;
38+
}
39+
40+
public double doubleMethod(double f) {
41+
return f;
42+
}
43+
44+
public int intMethod(int i) {
45+
return i;
46+
}
47+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
IntToX.class
3+
--function IntToX.byteCast
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
IntToX.class
3+
--function IntToX.charCast
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
IntToX.class
3+
--function IntToX.doubleCast
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
IntToX.class
3+
--function IntToX.floatCast
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
IntToX.class
3+
--function IntToX.longCast
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
IntToX.class
3+
--function IntToX.shortCast
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,15 @@ code_blockt java_bytecode_convert_methodt::convert_instructions(
15821582
PRECONDITION(op.size() == 1 && results.size() == 1);
15831583
typet type=java_type_from_char(statement[2]);
15841584
results[0] = typecast_exprt::conditional_cast(op[0], type);
1585+
1586+
// These types get converted/truncated then immediately turned back into
1587+
// ints again, so we just double-cast here.
1588+
if(
1589+
type == java_char_type() || type == java_byte_type() ||
1590+
type == java_short_type())
1591+
{
1592+
results[0] = typecast_exprt(results[0], java_int_type());
1593+
}
15851594
}
15861595
else if(statement=="new")
15871596
{

0 commit comments

Comments
 (0)