mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:58:32 +00:00
e36bc165c0
TEST=ffi/function_callbacks_structs_by_value_generated_test TEST=ffi/function_callbacks_structs_by_value_native_callable_generated_test TEST=ffi/regress_52399_test.dart Bug: https://github.com/dart-lang/sdk/issues/52399 Change-Id: Id16ccea5645d9b14a8f2726cb896b99266bba5a2 Cq-Include-Trybots: luci.dart.try:vm-msan-linux-release-x64-try,vm-aot-msan-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303360 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
55 lines
1.3 KiB
Dart
55 lines
1.3 KiB
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.
|
|
|
|
// SharedObjects=ffi_test_functions
|
|
|
|
import 'dart:ffi';
|
|
|
|
main() {
|
|
fine();
|
|
fine2();
|
|
repro52399();
|
|
}
|
|
|
|
const length = 8;
|
|
|
|
repro52399() {
|
|
final memory = malloc(length).cast<Int8>();
|
|
for (int i = 0; i < length; i++) {
|
|
memory[i] = 0;
|
|
}
|
|
final typedList1 = memory.asTypedList(length);
|
|
// MSAN unhappy when unoptimized, due to runtime entry.
|
|
final readVal = typedList1[0];
|
|
print(readVal);
|
|
free(memory);
|
|
}
|
|
|
|
fine() {
|
|
final memory = calloc(length, 1).cast<Int8>();
|
|
final typedList1 = memory.asTypedList(length);
|
|
final readVal = typedList1[0];
|
|
print(readVal);
|
|
free(memory);
|
|
}
|
|
|
|
fine2() {
|
|
final memory = malloc(length).cast<Int8>();
|
|
for (int i = 0; i < length; i++) {
|
|
memory[i] = 0;
|
|
}
|
|
final readVal = memory[0]; // MSAN doesn't see this one, it's force-optimized.
|
|
print(readVal);
|
|
free(memory);
|
|
}
|
|
|
|
@Native<Pointer<Void> Function(IntPtr num, IntPtr size)>(isLeaf: true)
|
|
external Pointer<Void> calloc(int num, int size);
|
|
|
|
@Native<Pointer<Void> Function(IntPtr)>(isLeaf: true)
|
|
external Pointer<Void> malloc(int size);
|
|
|
|
@Native<Void Function(Pointer)>(isLeaf: true)
|
|
external void free(Pointer pointer);
|