diff --git a/runtime/tests/vm/dart/regress_54128_test.dart b/runtime/tests/vm/dart/regress_54128_test.dart new file mode 100644 index 00000000000..e886c8e2479 --- /dev/null +++ b/runtime/tests/vm/dart/regress_54128_test.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// Regression test for https://github.com/dart-lang/sdk/issues/54128. +// Verifies that flow graph checker doesn't crash in debug mode +// after constant is propagated in the call argument but not its +// enviornment. + +@pragma('vm:never-inline') +void foo(int port) { + try { + print('hi'); + } catch (e) { + if (port != 0) rethrow; + bar(port); + } +} + +@pragma('vm:never-inline') +void bar(int x) { + print(x); +} + +void main() { + foo(int.parse('2')); + bar(int.parse('3')); +} diff --git a/runtime/vm/compiler/backend/flow_graph_checker.cc b/runtime/vm/compiler/backend/flow_graph_checker.cc index 92ae6a4fde5..a093d11e719 100644 --- a/runtime/vm/compiler/backend/flow_graph_checker.cc +++ b/runtime/vm/compiler/backend/flow_graph_checker.cc @@ -532,6 +532,12 @@ void FlowGraphChecker::AssertArgumentsInEnv(Definition* call) { // Redefinition instructions and boxing/unboxing are inserted // without updating environment uses (FlowGraph::RenameDominatedUses, // FlowGraph::InsertConversionsFor). + // + // Conditional constant propagation doesn't update environments either + // and may also replace redefinition instructions with constants + // without updating environment uses of their original definitions + // (ConstantPropagator::InsertRedefinitionsAfterEqualityComparisons). + // // Also, constants may belong to different blocks (e.g. function entry // and graph entry). Definition* arg_def = @@ -540,11 +546,8 @@ void FlowGraphChecker::AssertArgumentsInEnv(Definition* call) { env->ValueAt(env_base + i) ->definition() ->OriginalDefinitionIgnoreBoxingAndConstraints(); - ASSERT2((arg_def == env_def) || - (arg_def->IsConstant() && env_def->IsConstant() && - arg_def->AsConstant()->value().ptr() == - env_def->AsConstant()->value().ptr()), - arg_def, env_def); + ASSERT2((arg_def == env_def) || arg_def->IsConstant(), arg_def, + env_def); } } }