nodejs/deps/v8/test/mjsunit/regress/regress-1510761.js
Michaël Zasso 09a8440b45
deps: update V8 to 12.2.281.27
PR-URL: https://github.com/nodejs/node/pull/51362
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-03-31 15:36:07 +02:00

45 lines
1.3 KiB
JavaScript

// Copyright 2023 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.
//
// Note: The turboshaft-assert-types is needed (at least for these reproducer
// functions) to reach the VisitInt64XXXWithOverflow during instruction
// selection.
//
// Flags: --allow-natives-syntax --turboshaft-assert-types
function add(a, b) {
return a + b;
}
function sub(a, b) {
return a - b;
}
function mul(a, b) {
return a * b;
}
let int64Max = 9223372036854775807n;
%PrepareFunctionForOptimization(add);
assertEquals(3n, add(1n, 2n));
%OptimizeFunctionOnNextCall(add);
assertEquals(3n, add(1n, 2n));
// This will cause an overflow on the int64.
assertEquals(int64Max + int64Max, add(int64Max, int64Max));
%PrepareFunctionForOptimization(sub);
assertEquals(-1n, sub(1n, 2n));
%OptimizeFunctionOnNextCall(sub);
assertEquals(-1n, sub(1n, 2n));
// This will cause an overflow on the int64.
assertEquals(int64Max + int64Max, sub(int64Max, -int64Max));
%PrepareFunctionForOptimization(mul);
assertEquals(6n, mul(2n, 3n));
%OptimizeFunctionOnNextCall(mul);
assertEquals(6n, mul(2n, 3n));
// This will cause an overflow on the int64.
assertEquals(int64Max * int64Max, mul(int64Max, int64Max));