changeset 21126:6e05dd55d795

Merge
author Stefan Anzinger <stefan.anzinger@oracle.com>
date Mon, 27 Apr 2015 18:37:10 +0200
parents 41f048caa3dd b625b459cf45
children 647f571f54da
files
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java	Mon Apr 27 18:36:16 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java	Mon Apr 27 18:37:10 2015 +0200
@@ -41,10 +41,16 @@
         super(src);
     }
 
-    @Specialization
-    protected long div(long left, long right) {
-        /* No overflow is possible on a division. */
-        return left / right;
+    @Specialization(rewriteOn = ArithmeticException.class)
+    protected long div(long left, long right) throws ArithmeticException {
+        long result = left / right;
+        /*
+         * The division overflows if left is Long.MIN_VALUE and right is -1.
+         */
+        if ((left & right & result) < 0) {
+            throw new ArithmeticException("long overflow");
+        }
+        return result;
     }
 
     @Specialization