diff --git a/compile-only/AndiTest2.java b/compile-only/AndiTest2.java new file mode 100644 index 0000000000000000000000000000000000000000..2184f1ae393e18999e7c3558d9d2936c285e806c --- /dev/null +++ b/compile-only/AndiTest2.java @@ -0,0 +1,19 @@ +class Test { + public static void main(String[] args) { + Test test = new Test(); + Test result = test.run(); + if (result == null) + System.out.println(1); + else + System.out.println(0); + } + + public Test run() { + Test[] array = new Test[536870912 + 1]; /* no worries, if your OS is sane, memory won't be allocated until "touched" */ + array[536870912] = null; + array[0] = new Test(); + + return array[536870912]; /* 0x20000000 * 8, must not wrap around to 0 though */ + } + +} diff --git a/compile-only/FirmInfLoop.java b/compile-only/FirmInfLoop.java new file mode 100644 index 0000000000000000000000000000000000000000..486acf53dc51cdc7d6776046020a6531248ce0a8 --- /dev/null +++ b/compile-only/FirmInfLoop.java @@ -0,0 +1,10 @@ +/* Caused Infinite loop with --compile-firm + * Reason was the keepAlive edge added to loops + * */ +class a { + public static void main(String[] args) { + while (true) { + return; + } + } +} diff --git a/compile-only/NestedInfiniteLoops.java b/compile-only/NestedInfiniteLoops.java new file mode 100644 index 0000000000000000000000000000000000000000..d850010e30ccc4fe6b5e0a838a84f16de35c07d4 --- /dev/null +++ b/compile-only/NestedInfiniteLoops.java @@ -0,0 +1,5 @@ +class Test { + public static void main(String[] args) { + while(true) while(true); + } +} diff --git a/compile-only/Sudoku.java b/compile-only/Sudoku.java new file mode 100644 index 0000000000000000000000000000000000000000..893991f3a3b45e30b349443b40441a7337b8c20d --- /dev/null +++ b/compile-only/Sudoku.java @@ -0,0 +1,15 @@ +class C { + public static void main(String[] args) { } + public int field; + public void foo() { + int i = 0; + while (i < field) { + while (true) { + if (false) { + return; + } + } + i = i + 1; + } + } +} diff --git a/exec/AndiTest1.java b/exec/AndiTest1.java new file mode 100644 index 0000000000000000000000000000000000000000..e2ef6028a971dfdff744fb246783445f5258b189 --- /dev/null +++ b/exec/AndiTest1.java @@ -0,0 +1,27 @@ +class a { + public static void main(String[] args) { + new a().q(6,-7,8,-9,10); + } + + public void q(int a, int b, int c, int d, int e) { + System.out.println(a+b); + System.out.println(a+b+c); + System.out.println(a+b+c+d); + System.out.println(a+b+c+d+e); + System.out.println(a+3); + System.out.println(a+b+5); + System.out.println(5+(a+c)); + System.out.println(a*4); + System.out.println(a*5); + System.out.println((a+b)*8); + System.out.println(5+(b*4+c)); + System.out.println(5+(a+2*c)); + System.out.println(a+(b*2+(c*4+12+d))); + System.out.println(4*d+2*(a+3+8*(b+c*4))); + System.out.println(a*4+5); + System.out.println(a*9+5); + System.out.println((a+3)+5); + System.out.println(a*2-5); + System.out.println(a*2+(-5)); + } +} diff --git a/exec/AndiTest3.java b/exec/AndiTest3.java new file mode 100644 index 0000000000000000000000000000000000000000..eb0127f342e876edba4b5dfafcc61a796f5b4fbb --- /dev/null +++ b/exec/AndiTest3.java @@ -0,0 +1,46 @@ +class a { + public int ignored; + public static void main(String[] args) { + new a().q(); + if (new a().c_false()) { + int[] c_null = new int[-1]; + a o_null = null; + System.out.println(c_null[0]); + o_null.ignored = o_null.ignored(); + } + return; + } + + public boolean c_false() { + int i = 7; + int w = 9; + while (w < 200) { + i = i * i; + w = w * 2; + } + return i % 5 == 1; + } + + public int q() { + int[] c_null = new int[0]; + a o_null = null; + if (c_false()) { + int[] c_neg = new int[-32]; + int y = c_null[0]; + c_neg[0] = c_null[0] + o_null.ignored + o_null.ignored(); + return c_null[0]; + } + if (!c_false()) { + return 2; + } + int w = c_null[2]; + w = w + c_null[-1]; + w = w + c_null[0]; + c_null = new int[2 / 0]; + return w; + } + + public int ignored() { + return 43 % 0; + } +} diff --git a/exec/AndiTest4.java b/exec/AndiTest4.java new file mode 100644 index 0000000000000000000000000000000000000000..ddb101c0211a46f60df767347ff3a4179176f6a2 --- /dev/null +++ b/exec/AndiTest4.java @@ -0,0 +1,9 @@ +/* only with O0 */ +class a { + public static void main(String[] args) { + int x = 15352; + int y = 5; + y = x % (-y); + y = y/y - x%y; + } +} diff --git a/exec/BinaryMultiply.java b/exec/BinaryMultiply.java new file mode 100644 index 0000000000000000000000000000000000000000..8e5ee0a588cf2827e6e22f8bada081e2e5110d94 --- /dev/null +++ b/exec/BinaryMultiply.java @@ -0,0 +1,21 @@ +class a { + public static void main(String[] args) { + new a().mult(7,7); + } + + public int mult(int n, int m) { + int result = 0; + while (n > 0) { + + if (n % 2 != 0) { + result = result + m; + } + + System.out.println(m); + + m = m * 2; + n=n/2; + } + return result; + } +} diff --git a/exec/BoolArray.java b/exec/BoolArray.java new file mode 100644 index 0000000000000000000000000000000000000000..a6fde2073e8506e78bf0e39db16fb910aa888d09 --- /dev/null +++ b/exec/BoolArray.java @@ -0,0 +1,79 @@ +class Smol { + + public boolean[] boolArr; + + public Smol init() { + boolArr = new boolean[10]; + + clearBool(); + + return this; + } + + public void clearBool() { + int i = 0; + while(i < 10) { + boolArr[i] = false; + i = i + 1; + } + } + + public void setBool() { + int i = 0; + while(i < 10) { + boolArr[i] = true; + i = i + 1; + } + } + + public void testBool() { + int i; + int offset; + int step; + + clearBool(); + + step = 1; + while (step < 8) { + + offset = 0; + while (offset < step) { + + /* Set every 4th bool to true */ + i = 0; + while(i < 10) { + if (i % step == offset) { + boolArr[i] = true; + } + i = i + 1; + } + + i = 0; + while(i < 10) { + if (boolArr[i]) { + System.out.write(84); + } else { + System.out.write(70); + } + System.out.write(10); + i = i + 1; + } + + System.out.write(10); + + clearBool(); + offset = offset + 1; + } + + step = step + 1; + } + + System.out.flush(); + } + + public static void main(String[] args) { + Smol smol = new Smol().init(); + + smol.testBool(); + } +} diff --git a/exec/InfLoop2.java b/exec/InfLoop2.java new file mode 100644 index 0000000000000000000000000000000000000000..0100547e56b654e76e3d8f4d414cb1a273d625fa --- /dev/null +++ b/exec/InfLoop2.java @@ -0,0 +1,17 @@ +/* Infinite loop, leads to OOM */ +class a { + public static void main(String[] args) { + int n = 0; + int k = 0; + int[][] table = new int[n+1][]; + int i=0; + while (i<=n) { + table[i] = new int[i+1]; + int j=0; + while ((j<=i) && (j <= k)) { + j=j+1; + } + i=i+1; + } + } +} diff --git a/exec/MiniPhiDeconst.java b/exec/MiniPhiDeconst.java new file mode 100644 index 0000000000000000000000000000000000000000..a918bf32a6c8351c02a47ef438471b5d624dd72f --- /dev/null +++ b/exec/MiniPhiDeconst.java @@ -0,0 +1,23 @@ +class Test { + + public static void main(String[] args) { + int b = 1; + int d = 3; + int e = 4; + int f = 5; + + boolean run = true; + + while (run) { + + d = f; + b = e; + f = e; + + + System.out.println(d); + + run = false; + } + } +} diff --git a/exec/ModuloTest.java b/exec/ModuloTest.java new file mode 100644 index 0000000000000000000000000000000000000000..534b7cee767af7229dad41ac8b2f06e3761a2013 --- /dev/null +++ b/exec/ModuloTest.java @@ -0,0 +1,19 @@ +class ModuloTest { + public static void main(String[] args) { + new ModuloTest().q(61,-71,81,-91); + } + + public void q(int a, int b, int c, int d) { + System.out.println(a%1); + System.out.println(b%2); + System.out.println(c%4); + System.out.println(d%8); + System.out.println(a%(-1)); + System.out.println(b%(-2)); + System.out.println(c%(-4)); + System.out.println(d%(-8)); + System.out.println(c%(-32)); + System.out.println(a%2+c%(-4)%2+d%2); + System.out.println(d%53%32%8); + } +} diff --git a/exec/NestedLoopSegfault.inf.java b/exec/NestedLoopSegfault.inf.java new file mode 100644 index 0000000000000000000000000000000000000000..5a56c1057de25ef3455f0177f5e2e5e33ec5b72b --- /dev/null +++ b/exec/NestedLoopSegfault.inf.java @@ -0,0 +1,20 @@ +/* SEGFAULT */ +class a { + public static void main(String[] args) { + int n = 11; + int[] perm1 = new int[n]; + int[] count = new int[n]; + + {int i=0; while(i y2) { + int s = y1; + y1 = y2; + y2 = s; + } + int i = y1; + while (i <= y2) { + data[i][x] = color; + i = i + 1; + } + } + public void drawHorizontalLine(int color, int x1, int x2, int y) { + if (x1 > x2) { + int s = x1; + x1 = x2; + x2 = s; + } + int i = x1; + while (i <= x2) { + data[y][i] = color; + i = i + 1; + } + } + + public void drawLine(int color, int x1, int y1, int x2, int y2) { + if (x1 == x2) { + drawVerticalLine(color, x1, y1, y2); + return; + } + if (y1 == y2) { + drawHorizontalLine(color, x1, x2, y1); + return; + } + if (x1 > x2) { + int s = x1; + x1 = x2; + x2 = s; + s = y1; + y1 = y2; + y2 = s; + } + int dx = x2 - x1 + 1; + int dy = y2 - y1; + int dir = 1; + if (dy < 0) { + dy = dy * -1; + dir = -1; + } + dy = dy + 1; + int x = x1; + int y = y1; + if (dx >= dy) { + int ppl = dx / dy; + int rest = dx % dy; + while (y != y2 + dir) { + int thisline = ppl; + if (rest > 0) { + rest = rest - 1; + thisline = thisline + 1; + } + drawHorizontalLine(color, x, x + thisline - 1, y); + x = x + thisline; + y = y + dir; + } + } else { + int ppr = dy / dx; + int rest = dy % dx; + while (y != y2 + dir) { + int thisrow = ppr; + if (rest > 0) { + rest = rest - 1; + thisrow = thisrow + 1; + } + drawVerticalLine(color, x, y, y + thisrow - 1); + x = x + 1; + y = y + dir * thisrow; + } + } + } + + public void clear() { + int i = 0; + while (i < size) { + int j = 0; + while (j < size) { + data [i][j] = blank; + j = j + 1; + } + i = i + 1; + } + } + + public int convertLine(int l) { + int i = size - 1; + int pow = 1; + int res = 0; + while (i >= 0) { + res = res + data[l][i] * pow; + pow = pow * 10; + i = i - 1; + } + return res + prefix; + } + + public void print() { + int i = 0; + while (i < size) { + System.out.println(convertLine(i)); + i = i + 1; + } + } +} + +class Alphabet { + public int color; + + public void H(Img img) { + img.drawLine(color, 0, 0, 0, img.size - 1); + img.drawLine(color, img.size - 1, 0, img.size - 1, img.size - 1); + img.drawLine(color, 0, img.size / 2, img.size - 1, img.size / 2); + } + + public void E(Img img) { + img.drawLine(color, 0, 0, 0, img.size - 1); + img.drawLine(color, 0, 0, img.size - 1, 0); + img.drawLine(color, 0, img.size / 2, img.size - 1, img.size / 2); + img.drawLine(color, 0, img.size -1, img.size - 1, img.size -1); + } + + public void L(Img img) { + img.drawLine(color, 0, 0, 0, img.size - 1); + img.drawLine(color, 0, img.size -1, img.size - 1, img.size -1); + } + + public void O(Img img) { + img.drawLine(color, 0, img.size / 2, img.size / 2, 0); + img.drawLine(color, img.size / 2, 0, img.size - 1, img.size / 2); + img.drawLine(color, 0, img.size / 2, img.size / 2, img.size - 1); + img.drawLine(color, img.size / 2, img.size - 1, img.size - 1, img.size / 2); + } + + public void W(Img img) { + img.drawLine(color, 0, 0, 0, img.size - 1); + img.drawLine(color, img.size - 1, 0, img.size - 1, img.size - 1); + img.drawLine(color, 0, img.size - 1, img.size / 2, img.size / 2); + img.drawLine(color, img.size / 2, img.size / 2, img.size - 1, img.size - 1); + } + + public void R(Img img) { + img.drawLine(color, 0, 0, 0, img.size - 1); + img.drawLine(color, 0, 0, img.size - 1, 0); + img.drawLine(color, 0, img.size / 2, img.size - 1, img.size / 2); + img.drawLine(color, img.size - 1, 0, img.size - 1, img.size / 2); + img.drawLine(color, 0, img.size / 2, img.size - 1, img.size - 1); + } + + public void D(Img img) { + img.drawLine(color, 0, 0, 0, img.size - 1); + img.drawLine(color, 0, 0, img.size - 1, img.size / 2); + img.drawLine(color, 0, img.size - 1, img.size - 1, img.size / 2); + } + + public void print(Img img) { + img.print(); + img.clear(); + System.out.println(-1); + } + + public void HelloWorld(Img img) { + H(img); print(img); + E(img); print(img); + L(img); print(img); + L(img); print(img); + O(img); print(img); + print(img); + W(img); print(img); + O(img); print(img); + R(img); print(img); + L(img); print(img); + D(img); img.print(); + } +} +