# HG changeset patch # User Christian Humer # Date 1430148267 -7200 # Node ID b625b459cf459e3d788b587b2dc316602d997ef5 # Parent c92676a390b891765f449293f3291de79d229233 SL: fix division long overflow. Contributed-by: Raffaello Giulietti diff -r c92676a390b8 -r b625b459cf45 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java Mon Apr 27 11:55:51 2015 +0200 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLDivNode.java Mon Apr 27 17:24:27 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