v8/test/mjsunit/asm/regress-1027595.js
Michael Starzinger a3a0f80de9 [asm.js] Fix load type of {Float32Array} and {Float64Array}.
This makes sure that the return type of the aforementioned heap views is
always {float?} and {double?} respectively, independent of the type of
the value passed to the store. It fixes validation failures due to bogus
(and redundant) conversion expressions being emitted.

R=clemensb@chromium.org
TEST=mjsunit/asm/regress-1027595
BUG=chromium:1027595

Change-Id: I037613afc643ac1b04ae4a943e42dc1823ad5bdf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1932374
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65151}
2019-11-25 14:47:08 +00:00

45 lines
1.3 KiB
JavaScript

// 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 TestF32StoreConvertsF64ToF32() {
function Module(stdlib, foreign, heap) {
'use asm';
var f32 = new stdlib.Float32Array(heap);
function f(a) {
a = +a;
f32[0] = f32[1] = a;
}
return f;
}
var buffer = new ArrayBuffer(0x10000);
var f = Module(this, {}, buffer);
assertDoesNotThrow(() => f(23.42));
var view = new Float32Array(buffer);
assertEquals(Math.fround(23.42), view[0]);
assertEquals(Math.fround(23.42), view[1]);
assertTrue(%IsAsmWasmCode(Module));
})();
(function TestF64StoreConvertsF32ToF64() {
function Module(stdlib, foreign, heap) {
'use asm';
var fround = stdlib.Math.fround;
var f64 = new stdlib.Float64Array(heap);
function f(a) {
a = fround(a);
f64[0] = f64[1] = a;
}
return f;
}
var buffer = new ArrayBuffer(0x10000);
var f = Module(this, {}, buffer);
assertDoesNotThrow(() => f(23.42));
var view = new Float64Array(buffer);
assertEquals(Math.fround(23.42), view[0]);
assertEquals(Math.fround(23.42), view[1]);
assertTrue(%IsAsmWasmCode(Module));
})();