Skip to content

Commit f3d8167

Browse files
alexmarkovCommit Queue
authored andcommitted
[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 <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 2fbb33e commit f3d8167

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Regression test for b/378737064.
6+
//
7+
// Verifies that compiler doesn't crash after it incorrectly converts
8+
// null-aware int? comparison to IfThenElse.
9+
10+
import 'package:expect/expect.dart';
11+
12+
@pragma('vm:never-inline')
13+
int foo(int? x, int? y) => x == y ? 0 : 255;
14+
15+
main() {
16+
Expect.equals(0, foo(0, 0));
17+
Expect.equals(255, foo(0, 42));
18+
Expect.equals(0, foo(null, null));
19+
Expect.equals(255, foo(null, 0x1234567890));
20+
Expect.equals(0, foo(0x1234567890, 0x1234567890));
21+
Expect.equals(255, foo(0x1234567890, 0x1234567891));
22+
}

runtime/vm/compiler/backend/il.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6564,7 +6564,12 @@ bool IfThenElseInstr::Supports(ConditionInstr* condition,
65646564
// by if-conversion.
65656565
return !strict_compare->needs_number_check();
65666566
}
6567-
if (auto* comparison = condition->AsComparison()) {
6567+
if (auto* equality = condition->AsEqualityCompare()) {
6568+
// Non-smi comparisons are not supported by if-conversion.
6569+
return (equality->input_representation() == kTagged) &&
6570+
!equality->is_null_aware();
6571+
}
6572+
if (auto* comparison = condition->AsRelationalOp()) {
65686573
// Non-smi comparisons are not supported by if-conversion.
65696574
return comparison->input_representation() == kTagged;
65706575
}

0 commit comments

Comments
 (0)