publicclass Test5091921 { privatestaticint result = 0;
/* Test for the bug of transforming indx >= MININT to indx > MININT-1 */ publicstaticint test_ge1(int limit) { int indx; int sum = 0; for (indx = 500; indx >= limit; indx -= 2) {
sum += 2000 / indx;
result = sum;
} return sum;
}
/* Test for the bug of transforming indx <= MAXINT to indx < MAXINT+1 */ publicstaticint test_le1(int limit) { int indx; int sum = 0; for (indx = -500; indx <= limit; indx += 2)
{
sum += 3000 / indx;
result = sum;
} return sum;
}
/* Run with -Xcomp -XX:CompileOnly=wrap1.test1 -XX:MaxInlineSize=1 */ /* limit reset to ((limit-init+stride-1)/stride)*stride+init */ /* Calculation may overflow */ publicstaticvolatileint c = 1; publicstaticint test_wrap1(int limit)
{ int indx; int sum = 0; for (indx = 0xffffffff; indx < limit; indx += 0x20000000)
{
sum += c;
} return sum;
}
/* Test for range check elimination with bit flip issue for
scale*i+offset<limit where offset is not 0 */ staticint[] box5 = {1,2,3,4,5,6,7,8,9}; publicstaticint test_rce5(int[] b, int limit)
{ int indx; int sum = b[1];
result = sum; for (indx = 0x80000000; indx < limit; ++indx)
{ if (indx > 0x80000000)
{ // this test is not issued in pre-loop but issued in main loop // trick rce into thinking expression is false when indx >= 0 // in fact it is false when indx==0x80000001 if (indx - 9 < -9)
{
sum += indx;
result = sum;
sum ^= b[indx & 7];
result = sum;
} else break;
} else
{
sum += b[indx & 3];
result = sum;
}
} return sum;
}
/* Test for range check elimination with bit flip issue for
scale*i<limit where scale > 1 */ staticint[] box6 = {1,2,3,4,5,6,7,8,9}; publicstaticint test_rce6(int[] b, int limit)
{ int indx; int sum = b[1];
result = sum; for (indx = 0x80000000; indx < limit; ++indx)
{ if (indx > 0x80000000)
{ // harmless rce target if (indx < 0)
{
sum += result;
result = sum;
} else break; // this test is not issued in pre-loop but issued in main loop // trick rce into thinking expression is false when indx >= 0 // in fact it is false when indx==0x80000001 // In compilers that transform mulI to shiftI may mask this issue. if (indx * 28 + 1 < 0)
{
sum += indx;
result = sum;
sum ^= b[indx & 7];
result = sum;
} else break;
} else
{
sum += b[indx & 3];
result = sum;
}
} return sum;
}
/* Test for range check elimination with i <= limit */ staticint[] box7 = {1,2,3,4,5,6,7,8,9,0x7fffffff}; publicstaticint test_rce7(int[] b)
{ int indx; int max = b[9]; int sum = b[7];
result = sum; for (indx = 0; indx < b.length; ++indx)
{ if (indx <= max)
{
sum += (indx ^ 15) + ((result != 0) ? 0 : sum);
result = sum;
} else thrownew RuntimeException();
} for (indx = -7; indx < b.length; ++indx)
{ if (indx <= 9)
{
sum += (sum ^ 15) + ((result != 0) ? 0 : sum);
result = sum;
} else thrownew RuntimeException();
} return sum;
}
/* Test for range check elimination with i >= limit */ staticint[] box8 = {-1,0,1,2,3,4,5,6,7,8,0x80000000}; publicstaticint test_rce8(int[] b)
{ int indx; int sum = b[5]; int min = b[10];
result = sum; for (indx = b.length-1; indx >= 0; --indx)
{ if (indx >= min)
{
sum += (sum ^ 9) + ((result != 0) ? 0 :sum);
result = sum;
} else thrownew RuntimeException();
} return sum;
}
publicstaticvoid main(String[] args)
{
result=1; int r = 0; try {
r = test_ge1(0x80000000);
System.out.println(result);
System.out.println("test_ge1 FAILED");
System.exit(1);
} catch (ArithmeticException e1) {
System.out.println("test_ge1: Expected exception caught"); if (result != 5986) {
System.out.println(result);
System.out.println("test_ge1 FAILED");
System.exit(97);
}
}
System.out.println("test_ge1 WORKED");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.