dart-sdk/tests/ffi/regress_46127_test.dart
Daco Harkes 50640bdb81 [vm/ffi] Fix ia32 struct by value return with no arguments
On IA32 arguments are passed in registers. When a struct is returned
by value, a pointer is passed in on the stack containing the address to
which the return value is written. We did not account for this pointer
in the stack-height calculation.

This problem only surfaced when there are no arguments to the function.
Because if an argument is passed it has a higher stack height than the
pointer for the result being passed in.

Fix in: runtime/vm/compiler/ffi/native_calling_convention.cc

TEST=runtime/vm/compiler/ffi/native_calling_convention_test.cc
TEST=tests/ffi/regress_46127_test.dart

Closes: https://github.com/dart-lang/sdk/issues/46127

Change-Id: Ia78fe07cc7e3a3c8625143d491935a959b4a7895
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-precomp-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201269
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2021-05-26 13:37:32 +00:00

26 lines
653 B
Dart

// 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.
//
// SharedObjects=ffi_test_functions
import 'dart:ffi';
import "package:expect/expect.dart";
import 'dylib_utils.dart';
final nativeLib = dlopenPlatformSpecific("ffi_test_functions");
class Struct46127 extends Struct {
@Uint64()
external int val;
}
void main() {
final struct =
nativeLib.lookupFunction<Struct46127 Function(), Struct46127 Function()>(
'Regress46127')();
Expect.equals(123, struct.val);
}