forked from dart-lang/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/ffi] Fix representation of value for 8-bit and 16-bit FFI loads a…
…nd stores Previously, FFI store could use kUnboxedUint32 for value being stored via 8-bit or 16-bit StoreIndexed instruction. However, such StoreIndexed instructions require kUnboxedIntPtr representation. Due to the mismatch in the representations, SelectRepresentations pass inserts a speculative (deoptimizing) IntConverter instruction, which cases crash in AOT mode. Similar problem exists for FFI loads. This change corrects representation when unboxing value in the body of FFI store intrinsics and when boxing the value in FFI loads, so representation of the value matches representation required by StoreIndexed / returned by LoadIndexed. TEST=ffi/regress_flutter79441_test Fixes flutter/flutter#79441 Change-Id: Ida144e8d2e7a69d6767c9d4447bb20e79d847d48 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193824 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
- Loading branch information
1 parent
1bf4b0c
commit 707cd92
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
// Regression test for https://github.com/flutter/flutter/issues/79441. | ||
|
||
import 'dart:ffi'; | ||
|
||
// FFI signature | ||
typedef _dart_memset = void Function(Pointer<Uint8>, int, int); | ||
typedef _c_memset = Void Function(Pointer<Uint8>, Int32, IntPtr); | ||
|
||
_dart_memset? fbMemset; | ||
|
||
void _fallbackMemset(Pointer<Uint8> ptr, int byte, int size) { | ||
final bytes = ptr.cast<Uint8>(); | ||
for (var i = 0; i < size; i++) { | ||
bytes[i] = byte; | ||
} | ||
} | ||
|
||
void main() { | ||
try { | ||
fbMemset = DynamicLibrary.process() | ||
.lookupFunction<_c_memset, _dart_memset>('memset'); | ||
} catch (_) { | ||
// This works: | ||
// fbMemset = _fallbackMemset; | ||
|
||
// This doesn't: /aot/precompiler.cc: 2761: error: unreachable code | ||
fbMemset = (Pointer<Uint8> ptr, int byte, int size) { | ||
final bytes = ptr.cast<Uint8>(); | ||
for (var i = 0; i < size; i++) { | ||
bytes[i] = byte; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
// Regression test for https://github.com/flutter/flutter/issues/79441. | ||
|
||
import 'dart:ffi'; | ||
|
||
// FFI signature | ||
typedef _dart_memset = void Function(Pointer<Uint8>, int, int); | ||
typedef _c_memset = Void Function(Pointer<Uint8>, Int32, IntPtr); | ||
|
||
_dart_memset fbMemset; | ||
|
||
void _fallbackMemset(Pointer<Uint8> ptr, int byte, int size) { | ||
final bytes = ptr.cast<Uint8>(); | ||
for (var i = 0; i < size; i++) { | ||
bytes[i] = byte; | ||
} | ||
} | ||
|
||
void main() { | ||
try { | ||
fbMemset = DynamicLibrary.process() | ||
.lookupFunction<_c_memset, _dart_memset>('memset'); | ||
} catch (_) { | ||
// This works: | ||
// fbMemset = _fallbackMemset; | ||
|
||
// This doesn't: /aot/precompiler.cc: 2761: error: unreachable code | ||
fbMemset = (Pointer<Uint8> ptr, int byte, int size) { | ||
final bytes = ptr.cast<Uint8>(); | ||
for (var i = 0; i < size; i++) { | ||
bytes[i] = byte; | ||
} | ||
}; | ||
} | ||
} |