Skip to content

Commit dc03a6d

Browse files
victorgomesV8 LUCI CQ
authored andcommitted
[maglev] Check value before inlining Object builtin
Fixed: 363983041 Change-Id: I9b8520518a8bc6fde740cdced5c23e62c159b832 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5833384 Commit-Queue: Victor Gomes <[email protected]> Auto-Submit: Victor Gomes <[email protected]> Commit-Queue: Patrick Thier <[email protected]> Reviewed-by: Patrick Thier <[email protected]> Cr-Commit-Position: refs/heads/main@{#95924}
1 parent 38a51b4 commit dc03a6d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/maglev/maglev-graph-builder.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10292,7 +10292,8 @@ ReduceResult MaglevGraphBuilder::TryReduceConstructArrayConstructor(
1029210292

1029310293
ReduceResult MaglevGraphBuilder::TryReduceConstructBuiltin(
1029410294
compiler::JSFunctionRef builtin,
10295-
compiler::SharedFunctionInfoRef shared_function_info, CallArguments& args) {
10295+
compiler::SharedFunctionInfoRef shared_function_info, ValueNode* target,
10296+
CallArguments& args) {
1029610297
// TODO(victorgomes): specialize more known constants builtin targets.
1029710298
switch (shared_function_info.builtin_id()) {
1029810299
case Builtin::kArrayConstructor: {
@@ -10303,6 +10304,7 @@ ReduceResult MaglevGraphBuilder::TryReduceConstructBuiltin(
1030310304
// If no value is passed, we can immediately lower to a simple
1030410305
// constructor.
1030510306
if (args.count() == 0) {
10307+
RETURN_IF_ABORT(BuildCheckValue(target, builtin));
1030610308
ValueNode* result = BuildInlinedAllocation(CreateJSConstructor(builtin),
1030710309
AllocationType::kYoung);
1030810310
// TODO(leszeks): Don't eagerly clear the raw allocation, have the
@@ -10432,8 +10434,8 @@ ReduceResult MaglevGraphBuilder::TryReduceConstruct(
1043210434
}
1043310435

1043410436
if (shared_function_info.HasBuiltinId()) {
10435-
RETURN_IF_DONE(
10436-
TryReduceConstructBuiltin(function, shared_function_info, args));
10437+
RETURN_IF_DONE(TryReduceConstructBuiltin(function, shared_function_info,
10438+
target, args));
1043710439
}
1043810440

1043910441
if (shared_function_info.construct_as_builtin()) {

src/maglev/maglev-graph-builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ class MaglevGraphBuilder {
20562056
compiler::OptionalAllocationSiteRef maybe_allocation_site = {});
20572057
ReduceResult TryReduceConstructBuiltin(
20582058
compiler::JSFunctionRef builtin,
2059-
compiler::SharedFunctionInfoRef shared_function_info,
2059+
compiler::SharedFunctionInfoRef shared_function_info, ValueNode* target,
20602060
CallArguments& args);
20612061
ReduceResult TryReduceConstructGeneric(
20622062
compiler::JSFunctionRef function,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2024 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
//
5+
// Flags: --allow-natives-syntax
6+
7+
function foo(x) {
8+
return new x();
9+
}
10+
11+
%PrepareFunctionForOptimization(foo);
12+
foo(Object);
13+
%OptimizeFunctionOnNextCall(foo);
14+
assertThrows(foo, TypeError);

0 commit comments

Comments
 (0)