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...

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/14617014

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14629 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d9195153
...@@ -3341,6 +3341,9 @@ HInstruction* HMod::New( ...@@ -3341,6 +3341,9 @@ HInstruction* HMod::New(
if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) { if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) {
int32_t dividend = c_left->Integer32Value(); int32_t dividend = c_left->Integer32Value();
int32_t divisor = c_right->Integer32Value(); int32_t divisor = c_right->Integer32Value();
if (dividend == kMinInt && divisor == -1) {
return H_CONSTANT_DOUBLE(-0.0);
}
if (divisor != 0) { if (divisor != 0) {
int32_t res = dividend % divisor; int32_t res = dividend % divisor;
if ((res == 0) && (dividend < 0)) { if ((res == 0) && (dividend < 0)) {
......
...@@ -256,3 +256,12 @@ test(function stringCharAt() { ...@@ -256,3 +256,12 @@ test(function stringCharAt() {
assertEquals("b", "abc".charAt(1.1)); assertEquals("b", "abc".charAt(1.1));
assertEquals("", "abc".charAt(4.1)); assertEquals("", "abc".charAt(4.1));
}); });
test(function int32Mod() {
assertEquals(-0, -2147483648 % (-1));
});
test(function int32Div() {
assertEquals(2147483648, -2147483648 / (-1));
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment