Commit 1512f893 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[asm] Fix globals initialized by '-0'

Those globals must have type float instead of int to preserve the sign
bit.

R=ahaas@chromium.org

Bug: chromium:1069173
Change-Id: I9769f47f087aaba94a6172118be44f70adeded0c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2379861Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69609}
parent 6bc80769
......@@ -459,9 +459,15 @@ void AsmJsParser::ValidateModuleVar(bool mutable_variable) {
if (uvalue > 0x7FFFFFFF) {
FAIL("Numeric literal out of range");
}
DeclareGlobal(info, mutable_variable,
mutable_variable ? AsmType::Int() : AsmType::Signed(),
kWasmI32, WasmInitExpr(-static_cast<int32_t>(uvalue)));
if (uvalue == 0) {
// '-0' is treated as float.
DeclareGlobal(info, mutable_variable, AsmType::Float(), kWasmF32,
WasmInitExpr(-0.f));
} else {
DeclareGlobal(info, mutable_variable,
mutable_variable ? AsmType::Int() : AsmType::Signed(),
kWasmI32, WasmInitExpr(-static_cast<int32_t>(uvalue)));
}
} else {
FAIL("Expected numeric literal");
}
......
// Copyright 2020 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 foo() {
"use asm";
const v = -0;
function bar() {
return v;
}
return { d: bar };
}
var m = foo();
assertEquals(-Infinity, 1 / m.d());
assertTrue(%IsAsmWasmCode(foo));
......@@ -345,6 +345,7 @@
'asm/call-annotation': [SKIP],
'asm/global-imports': [SKIP],
'asm/regress-1027595': [SKIP],
'asm/regress-1069173': [SKIP],
'asm/regress-913822': [SKIP],
'asm/regress-937650': [SKIP],
'asm/regress-9531': [SKIP],
......
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