[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 <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Alexander Markov
2024-11-12 22:40:28 +00:00
committed by Commit Queue
parent 2fbb33e4d8
commit f3d8167443
2 changed files with 28 additions and 1 deletions
@@ -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));
}
+6 -1
View File
@@ -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;
}