Skip to content

Commit

Permalink
[asm.js] Fix numeric literal negation in multiplication.
Browse files Browse the repository at this point in the history
[email protected]
TEST=mjsunit/asm/int32-mul
BUG=chromium:715482

Change-Id: I525e901fd6ade101999694a53d5147b6e4ccc2e5
Reviewed-on: https://chromium-review.googlesource.com/488024
Reviewed-by: Clemens Hammacher <[email protected]>
Commit-Queue: Michael Starzinger <[email protected]>
Cr-Commit-Position: refs/heads/master@{#44892}
  • Loading branch information
Michael Starzinger authored and Commit Bot committed Apr 26, 2017
1 parent c5bfc27 commit 8952aef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/asmjs/asm-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ AsmType* AsmJsParser::UnaryExpression() {
return ret;
}

// 6.8.8 MultaplicativeExpression
// 6.8.8 MultiplicativeExpression
AsmType* AsmJsParser::MultiplicativeExpression() {
uint32_t uvalue;
if (CheckForUnsignedBelow(0x100000, &uvalue)) {
Expand All @@ -1609,14 +1609,16 @@ AsmType* AsmJsParser::MultiplicativeExpression() {
if (!a->IsA(AsmType::Int())) {
FAILn("Expected int");
}
current_function_builder_->EmitI32Const(static_cast<int32_t>(uvalue));
int32_t value = static_cast<int32_t>(uvalue);
current_function_builder_->EmitI32Const(value);
current_function_builder_->Emit(kExprI32Mul);
return AsmType::Intish();
}
scanner_.Rewind();
} else if (Check('-')) {
if (CheckForUnsignedBelow(0x100000, &uvalue)) {
current_function_builder_->EmitI32Const(-static_cast<int32_t>(uvalue));
int32_t value = -static_cast<int32_t>(uvalue);
current_function_builder_->EmitI32Const(value);
if (Check('*')) {
AsmType* a;
RECURSEn(a = UnaryExpression());
Expand All @@ -1643,7 +1645,8 @@ AsmType* AsmJsParser::MultiplicativeExpression() {
if (!a->IsA(AsmType::Int())) {
FAILn("Integer multiply of expects int");
}
current_function_builder_->EmitI32Const(static_cast<int32_t>(uvalue));
int32_t value = -static_cast<int32_t>(uvalue);
current_function_builder_->EmitI32Const(value);
current_function_builder_->Emit(kExprI32Mul);
return AsmType::Intish();
}
Expand All @@ -1655,7 +1658,8 @@ AsmType* AsmJsParser::MultiplicativeExpression() {
if (!a->IsA(AsmType::Int())) {
FAILn("Integer multiply of expects int");
}
current_function_builder_->EmitI32Const(static_cast<int32_t>(uvalue));
int32_t value = static_cast<int32_t>(uvalue);
current_function_builder_->EmitI32Const(value);
current_function_builder_->Emit(kExprI32Mul);
return AsmType::Intish();
}
Expand Down
2 changes: 1 addition & 1 deletion src/asmjs/asm-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class AsmJsParser {
AsmType* MemberExpression(); // 6.8.5 MemberExpression
AsmType* AssignmentExpression(); // 6.8.6 AssignmentExpression
AsmType* UnaryExpression(); // 6.8.7 UnaryExpression
AsmType* MultiplicativeExpression(); // 6.8.8 MultaplicativeExpression
AsmType* MultiplicativeExpression(); // 6.8.8 MultiplicativeExpression
AsmType* AdditiveExpression(); // 6.8.9 AdditiveExpression
AsmType* ShiftExpression(); // 6.8.10 ShiftExpression
AsmType* RelationalExpression(); // 6.8.11 RelationalExpression
Expand Down
4 changes: 2 additions & 2 deletions test/mjsunit/asm/int32-mul.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Module(stdlib, foreign, heap) {
"use asm";
function f1(i) {
i = i|0;
return (i | 0) * 3 | 0;
return (i | 0) * -3 | 0;
}
function f2(i) {
i = i|0;
Expand All @@ -26,7 +26,7 @@ function Module(stdlib, foreign, heap) {
var m = Module(this, {}, new ArrayBuffer(1024));

for (var i = -2147483648; i < 2147483648; i += 3999771) {
assertEquals(i * 3 | 0, m.f1(i));
assertEquals(i * -3 | 0, m.f1(i));
assertEquals(i * 7 | 0, m.f2(i));
assertEquals(i * 1024 | 0, m.f3(i));
assertEquals(i * 333339 | 0, m.f4(i));
Expand Down

0 comments on commit 8952aef

Please sign in to comment.