Revision: 14629
Author:   [email protected]
Date:     Mon May 13 00:32:38 2013
Log:      Fixed constant folding in HMod.

We have to check for overflow before attempting to do a modulo operation,
otherwise Crankshaft itself segfaults on some platforms, e.g. ia32. Added tests
even for division, where the problem doesn't show up, just to be sure...

[email protected]

Review URL: https://codereview.chromium.org/14617014
http://code.google.com/p/v8/source/detail?r=14629

Modified:
 /branches/bleeding_edge/src/hydrogen-instructions.cc
 /branches/bleeding_edge/test/mjsunit/constant-folding-2.js

=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Fri May 10 05:19:34 2013 +++ /branches/bleeding_edge/src/hydrogen-instructions.cc Mon May 13 00:32:38 2013
@@ -3341,6 +3341,9 @@
     if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) {
       int32_t dividend = c_left->Integer32Value();
       int32_t divisor = c_right->Integer32Value();
+      if (dividend == kMinInt && divisor == -1) {
+        return H_CONSTANT_DOUBLE(-0.0);
+      }
       if (divisor != 0) {
         int32_t res = dividend % divisor;
         if ((res == 0) && (dividend < 0)) {
=======================================
--- /branches/bleeding_edge/test/mjsunit/constant-folding-2.js Thu Feb 21 03:40:37 2013 +++ /branches/bleeding_edge/test/mjsunit/constant-folding-2.js Mon May 13 00:32:38 2013
@@ -256,3 +256,12 @@
   assertEquals("b", "abc".charAt(1.1));
   assertEquals("", "abc".charAt(4.1));
 });
+
+
+test(function int32Mod() {
+  assertEquals(-0, -2147483648 % (-1));
+});
+
+test(function int32Div() {
+  assertEquals(2147483648, -2147483648 / (-1));
+});

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to