Skip to content

Commit 7d54287

Browse files
committed
fix new array instruction
1 parent e3d5093 commit 7d54287

11 files changed

+87
-64
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>magpiebridge</groupId>
77
<artifactId>irconverter</artifactId>
8-
<version>0.1.0</version>
8+
<version>0.1.1</version>
99
<packaging>jar</packaging>
1010
<name>IRConverter</name>
1111
<url>https://github.com/MagpieBridge/IRConverter</url>

src/main/java/magpiebridge/converter/InstructionConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ private Stmt convertNewInstruction(DebuggingInformation debugInfo, SSANewInstruc
648648
// TODO: size type unsure
649649
size = getLocal(IntType.v(), use);
650650
}
651-
rvalue = Jimple.v().newNewArrayExpr(type, size);
651+
Type baseType =
652+
converter.convertType(inst.getNewSite().getDeclaredType().getArrayElementType());
653+
rvalue = Jimple.v().newNewArrayExpr(baseType, size);
652654
} else {
653655
rvalue = Jimple.v().newNewExpr((RefType) type);
654656
}

src/main/java/magpiebridge/converter/WalaToSootIRConverter.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.ibm.wala.cast.java.translator.jdt.ecj.ECJClassLoaderFactory;
99
import com.ibm.wala.classLoader.ClassLoaderFactory;
1010
import com.ibm.wala.classLoader.IClass;
11+
import com.ibm.wala.classLoader.Module;
1112
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
1213
import com.ibm.wala.ipa.callgraph.AnalysisScope;
1314
import com.ibm.wala.ipa.cha.ClassHierarchyException;
@@ -22,6 +23,7 @@
2223
import java.io.FileNotFoundException;
2324
import java.io.IOException;
2425
import java.io.PrintWriter;
26+
import java.util.Collection;
2527
import java.util.Collections;
2628
import java.util.Iterator;
2729
import java.util.Set;
@@ -69,6 +71,25 @@ public WalaToSootIRConverter(
6971
factory = new ECJClassLoaderFactory(scope.getExclusions());
7072
}
7173

74+
public WalaToSootIRConverter(@Nonnull Collection<? extends Module> files, Set<String> libPath) {
75+
initializeSoot(libPath);
76+
this.classConverter = new ClassConverter();
77+
addScopesForJava();
78+
for (Module file : files) {
79+
scope.addToScope(JavaSourceAnalysisScope.SOURCE, file);
80+
}
81+
try {
82+
// add Jars to scope
83+
for (String libJar : libPath) {
84+
scope.addToScope(ClassLoaderReference.Primordial, new JarFile(libJar));
85+
}
86+
} catch (IOException e) {
87+
e.printStackTrace();
88+
}
89+
setExclusions(null);
90+
factory = new ECJClassLoaderFactory(scope.getExclusions());
91+
}
92+
7293
/**
7394
* Initialize soot options, override this if you want to set up the options differently.
7495
*

src/test/java/magpiebridge/converter/minimaltestsuite/java6/AccessArraysTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void defaultTest() {
1818
method,
1919
expectedBodyStmts(
2020
"r0 := @this: AccessArrays",
21-
"$r1 = newarray (int[])[3]",
21+
"$r1 = newarray (int)[3]",
2222
"$r1[0] = 1",
2323
"$r1[1] = 2",
2424
"$r1[2] = 3",
@@ -43,7 +43,7 @@ public void defaultTest() {
4343
method,
4444
expectedBodyStmts(
4545
"r0 := @this: AccessArrays",
46-
"$r1 = newarray (byte[])[3]",
46+
"$r1 = newarray (byte)[3]",
4747
"$r1[0] = 4",
4848
"$r1[1] = 5",
4949
"$r1[2] = 6",
@@ -67,7 +67,7 @@ public void defaultTest() {
6767
method,
6868
expectedBodyStmts(
6969
"r0 := @this: AccessArrays",
70-
"$r1 = newarray (short[])[3]",
70+
"$r1 = newarray (short)[3]",
7171
"$r1[0] = 10",
7272
"$r1[1] = 20",
7373
"$r1[2] = 30",
@@ -92,7 +92,7 @@ public void defaultTest() {
9292
method,
9393
expectedBodyStmts(
9494
"r0 := @this: AccessArrays",
95-
"$r1 = newarray (long[])[3]",
95+
"$r1 = newarray (long)[3]",
9696
"$r1[0] = 547087L",
9797
"$r1[1] = 564645L",
9898
"$r1[2] = 654786L",
@@ -117,7 +117,7 @@ public void defaultTest() {
117117
method,
118118
expectedBodyStmts(
119119
"r0 := @this: AccessArrays",
120-
"$r1 = newarray (float[])[4]",
120+
"$r1 = newarray (float)[4]",
121121
"$r1[0] = 3.14F",
122122
"$r1[1] = 5.46F",
123123
"$r1[2] = 2.987F",
@@ -143,7 +143,7 @@ public void defaultTest() {
143143
method,
144144
expectedBodyStmts(
145145
"r0 := @this: AccessArrays",
146-
"$r1 = newarray (double[])[2]",
146+
"$r1 = newarray (double)[2]",
147147
"$r1[0] = 6.765414",
148148
"$r1[1] = 9.676565646",
149149
"$d0 = 0.0",
@@ -166,7 +166,7 @@ public void defaultTest() {
166166
method,
167167
expectedBodyStmts(
168168
"r0 := @this: AccessArrays",
169-
"$r1 = newarray (boolean[])[2]",
169+
"$r1 = newarray (boolean)[2]",
170170
"$r1[0] = 1",
171171
"$r1[1] = 0",
172172
"$r2 = null",
@@ -189,7 +189,7 @@ public void defaultTest() {
189189
method,
190190
expectedBodyStmts(
191191
"r0 := @this: AccessArrays",
192-
"$r1 = newarray (char[])[3]",
192+
"$r1 = newarray (char)[3]",
193193
"$r1[0] = 65",
194194
"$r1[1] = 98",
195195
"$r1[2] = 38",
@@ -214,7 +214,7 @@ public void defaultTest() {
214214
method,
215215
expectedBodyStmts(
216216
"r0 := @this: AccessArrays",
217-
"$r1 = newarray (java.lang.String[])[2]",
217+
"$r1 = newarray (java.lang.String)[2]",
218218
"$r1[0] = \"Hello World\"",
219219
"$r1[1] = \"Greetings\"",
220220
"$r2 = null",

src/test/java/magpiebridge/converter/minimaltestsuite/java6/ForEachLoopTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public String getMethodSignature() {
2222
public List<String> expectedBodyStmts() {
2323
return Stream.of(
2424
"r0 := @this: ForEachLoop",
25-
"$r1 = newarray (int[])[9]",
25+
"$r1 = newarray (int)[9]",
2626
"$r1[0] = 10",
2727
"$r1[1] = 20",
2828
"$r1[2] = 30",

src/test/java/magpiebridge/converter/minimaltestsuite/java6/GenTypeParamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public List<String> expectedBodyStmts() {
2121
"r0 := @this: GenTypeParam",
2222
"$r1 = new java.util.ArrayList",
2323
"specialinvoke $r1.<java.util.ArrayList: void <init>(int)>(3)",
24-
"$r2 = newarray (java.lang.Object[])[3]",
24+
"$r2 = newarray (java.lang.Object)[3]",
2525
"$r2[0] = 1",
2626
"$r2[1] = 2",
2727
"$r2[2] = 3",

src/test/java/magpiebridge/converter/minimaltestsuite/java6/InitializeArraysWhileDeclarationTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void defaultTest() {
1818
method,
1919
expectedBodyStmts(
2020
"r0 := @this: InitializeArraysWhileDeclaration",
21-
"$r1 = newarray (int[])[3]",
21+
"$r1 = newarray (int)[3]",
2222
"$r1[0] = 1",
2323
"$r1[1] = 2",
2424
"$r1[2] = 3",
@@ -29,7 +29,7 @@ public void defaultTest() {
2929
method,
3030
expectedBodyStmts(
3131
"r0 := @this: InitializeArraysWhileDeclaration",
32-
"$r1 = newarray (byte[])[3]",
32+
"$r1 = newarray (byte)[3]",
3333
"$r1[0] = 4",
3434
"$r1[1] = 5",
3535
"$r1[2] = 6",
@@ -40,7 +40,7 @@ public void defaultTest() {
4040
method,
4141
expectedBodyStmts(
4242
"r0 := @this: InitializeArraysWhileDeclaration",
43-
"$r1 = newarray (short[])[3]",
43+
"$r1 = newarray (short)[3]",
4444
"$r1[0] = 10",
4545
"$r1[1] = 20",
4646
"$r1[2] = 30",
@@ -51,7 +51,7 @@ public void defaultTest() {
5151
method,
5252
expectedBodyStmts(
5353
"r0 := @this: InitializeArraysWhileDeclaration",
54-
"$r1 = newarray (long[])[3]",
54+
"$r1 = newarray (long)[3]",
5555
"$r1[0] = 547087L",
5656
"$r1[1] = 564645L",
5757
"$r1[2] = 654786L",
@@ -62,7 +62,7 @@ public void defaultTest() {
6262
method,
6363
expectedBodyStmts(
6464
"r0 := @this: InitializeArraysWhileDeclaration",
65-
"$r1 = newarray (float[])[4]",
65+
"$r1 = newarray (float)[4]",
6666
"$r1[0] = 3.14F",
6767
"$r1[1] = 5.46F",
6868
"$r1[2] = 2.987F",
@@ -74,7 +74,7 @@ public void defaultTest() {
7474
method,
7575
expectedBodyStmts(
7676
"r0 := @this: InitializeArraysWhileDeclaration",
77-
"$r1 = newarray (double[])[2]",
77+
"$r1 = newarray (double)[2]",
7878
"$r1[0] = 6.765414",
7979
"$r1[1] = 9.676565646",
8080
"return"));
@@ -84,7 +84,7 @@ public void defaultTest() {
8484
method,
8585
expectedBodyStmts(
8686
"r0 := @this: InitializeArraysWhileDeclaration",
87-
"$r1 = newarray (boolean[])[2]",
87+
"$r1 = newarray (boolean)[2]",
8888
"$r1[0] = 1",
8989
"$r1[1] = 0",
9090
"return"));
@@ -94,7 +94,7 @@ public void defaultTest() {
9494
method,
9595
expectedBodyStmts(
9696
"r0 := @this: InitializeArraysWhileDeclaration",
97-
"$r1 = newarray (char[])[3]",
97+
"$r1 = newarray (char)[3]",
9898
"$r1[0] = 65",
9999
"$r1[1] = 98",
100100
"$r1[2] = 38",
@@ -105,7 +105,7 @@ public void defaultTest() {
105105
method,
106106
expectedBodyStmts(
107107
"r0 := @this: InitializeArraysWhileDeclaration",
108-
"$r1 = newarray (java.lang.String[])[2]",
108+
"$r1 = newarray (java.lang.String)[2]",
109109
"$r1[0] = \"Hello World\"",
110110
"$r1[1] = \"Greetings\"",
111111
"return"));

src/test/java/magpiebridge/converter/minimaltestsuite/java6/InitializeArraysWithIndexTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void defaultTest() {
1919
method,
2020
expectedBodyStmts(
2121
"r0 := @this: InitializeArraysWithIndex",
22-
"$r1 = newarray (int[])[3]",
22+
"$r1 = newarray (int)[3]",
2323
"$r1[0] = 1",
2424
"$r1[1] = 2",
2525
"$r1[2] = 3",
@@ -30,7 +30,7 @@ public void defaultTest() {
3030
method,
3131
expectedBodyStmts(
3232
"r0 := @this: InitializeArraysWithIndex",
33-
"$r1 = newarray (byte[])[3]",
33+
"$r1 = newarray (byte)[3]",
3434
"$r1[0] = 4",
3535
"$r1[1] = 5",
3636
"$r1[2] = 6",
@@ -41,7 +41,7 @@ public void defaultTest() {
4141
method,
4242
expectedBodyStmts(
4343
"r0 := @this: InitializeArraysWithIndex",
44-
"$r1 = newarray (short[])[3]",
44+
"$r1 = newarray (short)[3]",
4545
"$r1[0] = 10",
4646
"$r1[1] = 20",
4747
"$r1[2] = 30",
@@ -52,7 +52,7 @@ public void defaultTest() {
5252
method,
5353
expectedBodyStmts(
5454
"r0 := @this: InitializeArraysWithIndex",
55-
"$r1 = newarray (long[])[3]",
55+
"$r1 = newarray (long)[3]",
5656
"$r1[0] = 547087L",
5757
"$r1[1] = 564645L",
5858
"$r1[2] = 654786L",
@@ -64,7 +64,7 @@ public void defaultTest() {
6464
method,
6565
expectedBodyStmts(
6666
"r0 := @this: InitializeArraysWithIndex",
67-
"$r1 = newarray (float[])[4]",
67+
"$r1 = newarray (float)[4]",
6868
"$r1[0] = 3.14F",
6969
"$r1[1] = 5.46F",
7070
"$r1[2] = 2.987F",
@@ -76,7 +76,7 @@ public void defaultTest() {
7676
method,
7777
expectedBodyStmts(
7878
"r0 := @this: InitializeArraysWithIndex",
79-
"$r1 = newarray (double[])[2]",
79+
"$r1 = newarray (double)[2]",
8080
"$r1[0] = 6.765414",
8181
"$r1[1] = 9.676565646",
8282
"return"));
@@ -86,7 +86,7 @@ public void defaultTest() {
8686
method,
8787
expectedBodyStmts(
8888
"r0 := @this: InitializeArraysWithIndex",
89-
"$r1 = newarray (boolean[])[2]",
89+
"$r1 = newarray (boolean)[2]",
9090
"$r1[0] = 1",
9191
"$r1[1] = 0",
9292
"return"));
@@ -96,7 +96,7 @@ public void defaultTest() {
9696
method,
9797
expectedBodyStmts(
9898
"r0 := @this: InitializeArraysWithIndex",
99-
"$r1 = newarray (char[])[3]",
99+
"$r1 = newarray (char)[3]",
100100
"$r1[0] = 65",
101101
"$r1[1] = 98",
102102
"$r1[2] = 38",
@@ -107,7 +107,7 @@ public void defaultTest() {
107107
method,
108108
expectedBodyStmts(
109109
"r0 := @this: InitializeArraysWithIndex",
110-
"$r1 = newarray (java.lang.String[])[2]",
110+
"$r1 = newarray (java.lang.String)[2]",
111111
"$r1[0] = \"Hello World\"",
112112
"$r1[1] = \"Greetings\"",
113113
"return"));

0 commit comments

Comments
 (0)