dart-sdk/tests/ffi_2/regress_51315_test.dart
Daco Harkes 6a90c21992 [vm/ffi] Fix MemoryCopyInstr on ia32
The MemoryCopyInstr destroys the value in src-TypedDataBase
location. It overwrites it by loading the data_ field.

This requires using a WritableRegister, rather than a Register.

This issue seems to have been already present before the recent
optimizations (the leaq instruction overwrites array_reg), but the
recent optimizations made it exercise this instruction in a loop where
it was assumed the src-position was not destroyed.

TEST=tests/ffi/regress_51315_test.dart

Closes: https://github.com/dart-lang/sdk/issues/51315
Change-Id: If37c6c39de8fd0cba9b8a25a1f38f025a39123d9
Cq-Include-Trybots: luci.dart.try:vm-kernel-win-debug-ia32-try,vm-kernel-nnbd-win-release-ia32-try,vm-kernel-nnbd-linux-release-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-eager-optimization-linux-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283021
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-02-14 13:20:43 +00:00

38 lines
782 B
Dart

// Copyright (c) 2023, 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.9
// VMOptions=--deterministic --optimization-counter-threshold=100
import 'dart:ffi';
import "package:ffi/ffi.dart";
main(List<String> arguments) {
for (int i = 0; i < 1000; i++) {
testCompoundLoadAndStore();
}
print('done');
}
const count = 10;
testCompoundLoadAndStore() {
final foos = calloc<Foo>(count);
final reference = foos.ref;
reference.a = count;
for (var j = 1; j < count; j++) {
final foo = foos.elementAt(j);
foo.ref = reference;
}
calloc.free(foos);
}
class Foo extends Struct {
@Int8()
int a;
}