912005267d
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680 Commit-Queue: Sigmund Cherem <sigmund@google.com> Reviewed-by: Joshua Litt <joshualitt@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com> Reviewed-by: Stephen Adams <sra@google.com>
41 lines
1.5 KiB
Dart
41 lines
1.5 KiB
Dart
// Copyright (c) 2013, 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.
|
|
|
|
// @dart = 2.7
|
|
|
|
// dart2js regression test where the SSA backend would use the wrong
|
|
// type for an instruction: when doing a speculative type propagation,
|
|
// if an instruction gets analyzed multiple times, we used to save the
|
|
// last inferred type, which could be speculative, instead of the
|
|
// first inferred type, which is the actual, non-speculative, type.
|
|
//
|
|
// Because we are doing speculative type propagation at the very end,
|
|
// before emitting the bailout version, the only place where we might
|
|
// do wrong optimizations is during the codegen. It turns out that the
|
|
// codegen optimizes '==' comparisons on null to '===' in case it knows
|
|
// the receiver cannot be null. So in the following example, the
|
|
// [:e == null:] comparison in [foo] got wrongly generated to a
|
|
// JavaScript identity check (that is, using '==='). But this
|
|
// comparison does not work for undefined, which the DOM sometimes
|
|
// returns.
|
|
|
|
import "native_testing.dart";
|
|
|
|
var a = 42;
|
|
var b = 0;
|
|
|
|
foo(e) {
|
|
// Loop to force a bailout.
|
|
for (int i = 0; i < b; i++) {
|
|
a = e[i]; // Will desire a readable primitive.
|
|
}
|
|
// Our heuristics for '==' on an indexable primitive is that it's
|
|
// more common to do it on string, so we'll want e to be a string.
|
|
return a == e || e == null;
|
|
}
|
|
|
|
main() {
|
|
Expect.isTrue(foo(JS('', 'void 0')));
|
|
}
|