Skip to content

Commit ad66cda

Browse files
Fixing long to char conversion
1 parent b7f4253 commit ad66cda

5 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Origin of the benchmark:
3+
* license: 4-clause BSD (see /java/jbmc-regression/LICENSE)
4+
* repo: https://github.com/diffblue/cbmc.git
5+
* branch: develop
6+
* directory: regression/cbmc-java/long1
7+
* The benchmark was taken from the repo: 24 January 2018
8+
*/
9+
10+
class Main {
11+
public static void main(String[] args) {
12+
long l = 4620693217682128896L;
13+
14+
// conversions
15+
int i = (int) l;
16+
char c = (char) l;
17+
float f = l;
18+
double d = l;
19+
short s = (short) l;
20+
21+
if (i >= 0) assert (long) i == (l & 0x7fffffff);
22+
23+
if (c >= 0) assert (long) c == (l & 0x7fff);
24+
25+
if (s >= 0) assert (long) s == (l & 0x7fff);
26+
}
27+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"warnings" : [ {
3+
"message" : "['Main.java':21:16] on 'void Main::main(java.lang.String*[]* args)': [EXPRESSION] DEFINITE: the assertion holds"
4+
}, {
5+
"message" : "['Main.java':23:16] on 'void Main::main(java.lang.String*[]* args)': [EXPRESSION] DEFINITE: the assertion holds"
6+
}, {
7+
"message" : "['Main.java':25:16] on 'void Main::main(java.lang.String*[]* args)': [EXPRESSION] DEFINITE: the assertion holds"
8+
} ],
9+
"files" : [ "report.json", "void_Main.main(java.lang.String_[]__args).json" ],
10+
"info" : {
11+
"cfgs" : "13",
12+
"duration" : "99ms",
13+
"end" : "2025-10-08T12:11:19.446+02:00",
14+
"expressions" : "80",
15+
"files" : "1",
16+
"globals" : "27",
17+
"members" : "143",
18+
"programs" : "1",
19+
"start" : "2025-10-08T12:11:19.347+02:00",
20+
"statements" : "34",
21+
"units" : "48",
22+
"version" : "0.1",
23+
"warnings" : "3"
24+
},
25+
"configuration" : {
26+
"analysisGraphs" : "NONE",
27+
"descendingPhaseType" : "NONE",
28+
"dumpForcesUnwinding" : "false",
29+
"fixpointWorkingSet" : "OrderBasedWorkingSet",
30+
"glbThreshold" : "5",
31+
"hotspots" : "unset",
32+
"jsonOutput" : "true",
33+
"openCallPolicy" : "ReturnTopPolicy",
34+
"optimize" : "false",
35+
"recursionWideningThreshold" : "5",
36+
"semanticChecks" : "AssertChecker",
37+
"serializeInputs" : "false",
38+
"serializeResults" : "true",
39+
"shouldSmashError" : "unset",
40+
"syntacticChecks" : "",
41+
"useWideningPoints" : "true",
42+
"wideningThreshold" : "5",
43+
"workdir" : "java-outputs/svcomp/long1"
44+
}
45+
}

jlisa/java-testcases/svcomp/long1/void_Main.main(java.lang.String_[]__args).json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

jlisa/src/main/java/it/unive/jlisa/analysis/value/ConstantPropagation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import it.unive.jlisa.program.operator.NaryExpression;
8383
import it.unive.jlisa.program.operator.NaryOperator;
8484
import it.unive.jlisa.program.type.JavaByteType;
85+
import it.unive.jlisa.program.type.JavaCharType;
8586
import it.unive.jlisa.program.type.JavaDoubleType;
8687
import it.unive.jlisa.program.type.JavaIntType;
8788
import it.unive.jlisa.program.type.JavaLongType;
@@ -1245,6 +1246,8 @@ else if (right.getValue() instanceof JavaLongType)
12451246
return new ConstantValue(((Number) left.getValue()).longValue());
12461247
else if (right.getValue() instanceof JavaDoubleType)
12471248
return new ConstantValue(((Number) left.getValue()).doubleValue());
1249+
else if (right.getValue() instanceof JavaCharType)
1250+
return new ConstantValue((int) (char) ((Number) left.getValue()).longValue());
12481251

12491252
return left;
12501253
}

jlisa/src/test/java/it/unive/jlisa/svcomp/SVCompTestcases.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,11 @@ public void swap1_test() throws IOException {
442442
"Main.java");
443443
perform(conf);
444444
}
445+
446+
@Test
447+
public void long1_test() throws IOException {
448+
CronConfiguration conf = TestHelpers.assertCheckerWithConstantPropagation("svcomp", "long1",
449+
"Main.java", "../common/");
450+
perform(conf);
451+
}
445452
}

0 commit comments

Comments
 (0)