Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: test/codegen/lib/typed_data/typed_data_load2_test.dart

Issue 1673863002: Infra for running lib tests (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Reformat Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/codegen/lib/typed_data/typed_data_load2_test.dart
diff --git a/test/codegen/lib/typed_data/typed_data_load2_test.dart b/test/codegen/lib/typed_data/typed_data_load2_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3775615f8b163484d22fbd168c7591e8b1ae180a
--- /dev/null
+++ b/test/codegen/lib/typed_data/typed_data_load2_test.dart
@@ -0,0 +1,107 @@
+// Copyright (c) 2014, 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.
+
+// Test that the compiler's load elimination phase sees interfering writes to
+// the array's buffer.
+
+import "dart:typed_data";
+import 'package:expect/expect.dart';
+
+aliasWithByteData1() {
+ var aa = new Int8List(10);
+ var b = new ByteData.view(aa.buffer);
+ for (int i = 0; i < aa.length; i++) aa[i] = 9;
+
+ var x1 = aa[3];
+ b.setInt8(3, 1);
+ var x2 = aa[3];
+
+ Expect.equals(9, x1);
+ Expect.equals(1, x2);
+}
+
+aliasWithByteData2() {
+ var b = new ByteData(10);
+ var aa = new Int8List.view(b.buffer);
+ for (int i = 0; i < aa.length; i++) aa[i] = 9;
+
+ var x1 = aa[3];
+ b.setInt8(3, 1);
+ var x2 = aa[3];
+
+ Expect.equals(9, x1);
+ Expect.equals(1, x2);
+}
+
+alias8x8() {
+ var buffer = new Int8List(10).buffer;
+ var a1 = new Int8List.view(buffer);
+ var a2 = new Int8List.view(buffer, 1);
+
+ for (int i = 0; i < a1.length; i++) a1[i] = 9;
+
+ // Different indexes that alias.
+ var x1 = a1[1];
+ a2[0] = 0;
+ var x2 = a1[1];
+ Expect.equals(9, x1);
+ Expect.equals(0, x2);
+
+ for (int i = 0; i < a1.length; i++) a1[i] = 9;
+
+ // Same indexes that don't alias.
+ x1 = a1[1];
+ a2[1] = 5;
+ x2 = a1[1];
+ Expect.equals(9, x1);
+ Expect.equals(9, x2);
+}
+
+alias8x16() {
+ var a1 = new Int8List(10);
+ var a2 = new Int16List.view(a1.buffer);
+
+ for (int i = 0; i < a1.length; i++) a1[i] = 9;
+
+ // Same indexes that alias.
+ var x1 = a1[0];
+ a2[0] = 0x101;
+ var x2 = a1[0];
+ Expect.equals(9, x1);
+ Expect.equals(1, x2);
+
+ for (int i = 0; i < a1.length; i++) a1[i] = 9;
+
+ // Different indexes that alias.
+ x1 = a1[4];
+ a2[2] = 0x505;
+ x2 = a1[4];
+ Expect.equals(9, x1);
+ Expect.equals(5, x2);
+
+ for (int i = 0; i < a1.length; i++) a1[i] = 9;
+
+ // Same indexes that don't alias.
+ x1 = a1[3];
+ a2[3] = 0x505;
+ x2 = a1[3];
+ Expect.equals(9, x1);
+ Expect.equals(9, x2);
+
+ for (int i = 0; i < a1.length; i++) a1[i] = 9;
+
+ // Different indexes don't alias.
+ x1 = a1[2];
+ a2[0] = 0x505;
+ x2 = a1[2];
+ Expect.equals(9, x1);
+ Expect.equals(9, x2);
+}
+
+main() {
+ aliasWithByteData1();
+ aliasWithByteData2();
+ alias8x8();
+ alias8x16();
+}
« no previous file with comments | « test/codegen/lib/typed_data/typed_data_list_test.dart ('k') | test/codegen/lib/typed_data/typed_data_load_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698