Commit b60d5674 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[asm.js] Fix undefined behavior with float32 constants.

R=jkummerow@chromium.org
TEST=mjsunit/asm/regress-937650
BUG=chromium:937650

Change-Id: I9a46fcce68cf1b5c424539aad2f78fbcd30cf9b1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1505458Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60080}
parent a59ca735
......@@ -13,6 +13,7 @@
#include "src/asmjs/asm-types.h"
#include "src/base/optional.h"
#include "src/base/overflowing-math.h"
#include "src/conversions-inl.h"
#include "src/flags.h"
#include "src/parsing/scanner.h"
#include "src/wasm/wasm-limits.h"
......@@ -520,7 +521,7 @@ void AsmJsParser::ValidateModuleVarFromGlobal(VarInfo* info,
dvalue = -dvalue;
}
DeclareGlobal(info, mutable_variable, AsmType::Float(), kWasmF32,
WasmInitExpr(static_cast<float>(dvalue)));
WasmInitExpr(DoubleToFloat32(dvalue)));
} else if (CheckForUnsigned(&uvalue)) {
dvalue = uvalue;
if (negate) {
......
// Copyright 2019 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(stdlib) {
"use asm";
var fround = stdlib.Math.fround;
// The below constant is outside the range of representable {float} values.
const infinity = fround(1.7976931348623157e+308);
function f() {
return infinity;
}
return { f: f };
}
var m = Module(this);
assertEquals(Infinity, m.f());
assertTrue(%IsAsmWasmCode(Module));
......@@ -361,6 +361,7 @@
'asm/call-annotation': [SKIP],
'asm/global-imports': [SKIP],
'asm/regress-913822': [SKIP],
'asm/regress-937650': [SKIP],
'asm/return-types': [SKIP],
'regress/regress-599719': [SKIP],
'regress/regress-6196': [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