diff --git a/runtime/tests/vm/dart/regress_b378737064_test.dart b/runtime/tests/vm/dart/regress_b378737064_test.dart new file mode 100644 index 00000000000..339dfdca8d7 --- /dev/null +++ b/runtime/tests/vm/dart/regress_b378737064_test.dart @@ -0,0 +1,22 @@ +// Copyright (c) 2024, 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 b/378737064. +// +// Verifies that compiler doesn't crash after it incorrectly converts +// null-aware int? comparison to IfThenElse. + +import 'package:expect/expect.dart'; + +@pragma('vm:never-inline') +int foo(int? x, int? y) => x == y ? 0 : 255; + +main() { + Expect.equals(0, foo(0, 0)); + Expect.equals(255, foo(0, 42)); + Expect.equals(0, foo(null, null)); + Expect.equals(255, foo(null, 0x1234567890)); + Expect.equals(0, foo(0x1234567890, 0x1234567890)); + Expect.equals(255, foo(0x1234567890, 0x1234567891)); +} diff --git a/runtime/vm/compiler/backend/il.cc b/runtime/vm/compiler/backend/il.cc index daaf8e4a8a2..17bca748c0d 100644 --- a/runtime/vm/compiler/backend/il.cc +++ b/runtime/vm/compiler/backend/il.cc @@ -6564,7 +6564,12 @@ bool IfThenElseInstr::Supports(ConditionInstr* condition, // by if-conversion. return !strict_compare->needs_number_check(); } - if (auto* comparison = condition->AsComparison()) { + if (auto* equality = condition->AsEqualityCompare()) { + // Non-smi comparisons are not supported by if-conversion. + return (equality->input_representation() == kTagged) && + !equality->is_null_aware(); + } + if (auto* comparison = condition->AsRelationalOp()) { // Non-smi comparisons are not supported by if-conversion. return comparison->input_representation() == kTagged; }