dart-sdk/tests/standalone_2/array_bounds_check_generalization_test.dart
Michael Thomsen e4cc3c98e5 [3.0 alpha] Remove deprecated dart:core List() constructor.
TEST=ci

Bug: Contributes to https://github.com/dart-lang/sdk/issues/49529
Change-Id: Ic129ef2d89f625d9ec6a7a1c301cffddd60b2ff7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258920
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Michael Thomsen <mit@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2022-12-15 11:36:22 +00:00

92 lines
2 KiB
Dart

// Copyright (c) 2012, 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.
//
// We are using --complete-timeline below to ensure that we get timeline events
// generated during all phases of compilation and deoptimization.
// VMOptions=--optimization_counter_threshold=10 --no-use-osr --complete-timeline --no-background_compilation
// @dart = 2.9
import "package:expect/expect.dart";
test1(a, start, step, N) {
var e;
for (var i = 0; i < N; i++) {
e = a[start + i * step];
}
return e;
}
test2(a, b) {
var e;
for (var i = 0, j = 0, k = 0; i < a.length; i++, j++, k++) {
e = b[k] = a[j];
}
return e;
}
test3(a, b) {
var e;
for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
e = b[k] = a[j - 1];
}
return e;
}
test4(a, b) {
var e;
if (a.length < 2) {
return null;
}
for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
e = b[k] = a[j - 1];
}
return e;
}
test5(a, b, k0) {
var e;
if (a.length < 2) {
return null;
}
if (k0 > 1) {
return null;
}
for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
e = b[k - k0] = a[j - 1];
}
return e;
}
test6(a, M, N) {
var e = 0;
for (var i = 0; i < N; i++) {
for (var j = 0; j < M; j++) {
e += a[i * M + j];
}
}
return e;
}
main() {
var a = const [0, 1, 2, 3, 4, 5, 6, 7];
var b = new List<dynamic>.filled(a.length, null);
for (var i = 0; i < 10000; i++) {
Expect.equals(a.last, test1(a, 0, 1, a.length));
Expect.equals(a.last, test2(a, b));
Expect.equals(a[a.length - 2], test3(a, b));
Expect.equals(a[a.length - 2], test4(a, b));
Expect.equals(a[a.length - 2], test5(a, b, 0));
Expect.equals(6, test6(a, 2, 2));
}
test1(a, 0, 2, a.length ~/ 2);
Expect.throws(() => test1(a, 1, 1, a.length));
Expect.throws(() => test2(a, new List<dynamic>.filled(a.length - 1, null)));
Expect.throws(() => test6(a, 4, 3));
}