From f3d81674439b6d60e660c2c5428d4cd9e65abb9a Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Tue, 12 Nov 2024 22:40:28 +0000 Subject: [PATCH] [vm/compiler] Do not convert null-aware int? equality to IfThenElse IfThenElse instruction expects a simple Smi comparison and it doesn't support null-aware int? comparison (although it uses the same kTagged representation). TEST=runtime/tests/vm/dart/regress_b378737064_test.dart Fixes b/378737064 Change-Id: Iaf9243ff5505b986bbfe4510834972e75869dc61 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394570 Commit-Queue: Alexander Markov Reviewed-by: Ryan Macnak --- .../vm/dart/regress_b378737064_test.dart | 22 +++++++++++++++++++ runtime/vm/compiler/backend/il.cc | 7 +++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 runtime/tests/vm/dart/regress_b378737064_test.dart 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; }