diff --git a/src/asmjs/asm-parser.cc b/src/asmjs/asm-parser.cc index f0c535ed8b..0fbc238613 100644 --- a/src/asmjs/asm-parser.cc +++ b/src/asmjs/asm-parser.cc @@ -1642,6 +1642,7 @@ AsmType* AsmJsParser::UnaryExpression() { // 6.8.8 MultiplicativeExpression AsmType* AsmJsParser::MultiplicativeExpression() { + AsmType* a; uint32_t uvalue; if (CheckForUnsignedBelow(0x100000, &uvalue)) { if (Check('*')) { @@ -1654,8 +1655,10 @@ AsmType* AsmJsParser::MultiplicativeExpression() { current_function_builder_->EmitI32Const(value); current_function_builder_->Emit(kExprI32Mul); return AsmType::Intish(); + } else { + scanner_.Rewind(); + RECURSEn(a = UnaryExpression()); } - scanner_.Rewind(); } else if (Check('-')) { if (CheckForUnsignedBelow(0x100000, &uvalue)) { int32_t value = -static_cast(uvalue); @@ -1669,12 +1672,14 @@ AsmType* AsmJsParser::MultiplicativeExpression() { current_function_builder_->Emit(kExprI32Mul); return AsmType::Intish(); } - return AsmType::Signed(); + a = AsmType::Signed(); + } else { + scanner_.Rewind(); + RECURSEn(a = UnaryExpression()); } - scanner_.Rewind(); + } else { + RECURSEn(a = UnaryExpression()); } - AsmType* a; - RECURSEn(a = UnaryExpression()); for (;;) { if (Check('*')) { uint32_t uvalue; diff --git a/test/mjsunit/regress/regress-8377.js b/test/mjsunit/regress/regress-8377.js new file mode 100644 index 0000000000..32d2eb74fb --- /dev/null +++ b/test/mjsunit/regress/regress-8377.js @@ -0,0 +1,24 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --allow-natives-syntax + +function Module(global, env, buffer) { + "use asm"; + function test1() { + var x = 0; + x = -1 / 1 | 0; + return x | 0; + } + function test2() { + var x = 0; + x = (-1 / 1) | 0; + return x | 0; + } + return { test1: test1, test2: test2 }; +}; +let module = Module(this); +assertEquals(-1, module.test1()); +assertEquals(-1, module.test2()); +assertTrue(%IsAsmWasmCode(Module));