[vm/ffi] Test alignment of small stack arguments

Test exercises alignment on stack, will currently fail on iOS arm64.

In addition, the Dart functions used as callbacks in tests now print their arguments for debugging purposes.

Issue: https://github.com/dart-lang/sdk/issues/39637

Splitting test off large CL (https://dart-review.googlesource.com/c/sdk/+/129081) to be able to land separately.

Change-Id: Iba3c63338f5d91d6e3819e54c166bbfade48d53f
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131074
Reviewed-by: Teagan Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
Daco Harkes 2020-01-14 10:50:25 +00:00 committed by commit-bot@chromium.org
parent d08f070b28
commit a228bf5e1a
4 changed files with 67 additions and 5 deletions

View file

@ -186,6 +186,28 @@ DART_EXPORT intptr_t SumManyInts(intptr_t a,
return retval;
}
// Sums many ints.
// Used for testing calling conventions. With small integers on stack slots we
// test stack alignment.
DART_EXPORT int16_t SumManySmallInts(int8_t a,
int16_t b,
int8_t c,
int16_t d,
int8_t e,
int16_t f,
int8_t g,
int16_t h,
int8_t i,
int16_t j) {
std::cout << "SumManySmallInts(" << static_cast<int>(a) << ", " << b << ", "
<< static_cast<int>(c) << ", " << d << ", " << static_cast<int>(e)
<< ", " << f << ", " << static_cast<int>(g) << ", " << h << ", "
<< static_cast<int>(i) << ", " << j << ")\n";
int16_t retval = a + b + c + d + e + f + g + h + i + j;
std::cout << "returning " << retval << "\n";
return retval;
}
// Sums an odd number of ints.
// Used for testing calling conventions. With so many arguments, and an odd
// number of arguments, we are testing stack alignment on various architectures.

View file

@ -20,6 +20,8 @@ typedef NativeDoubleUnaryOp = Double Function(Double);
typedef NativeFloatUnaryOp = Float Function(Float);
typedef NativeDecenaryOp = IntPtr Function(IntPtr, IntPtr, IntPtr, IntPtr,
IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr);
typedef NativeDecenaryOp2 = Int16 Function(
Int8, Int16, Int8, Int16, Int8, Int16, Int8, Int16, Int8, Int16);
typedef NativeDoubleDecenaryOp = Double Function(Double, Double, Double, Double,
Double, Double, Double, Double, Double, Double);
typedef NativeVigesimalOp = Double Function(
@ -149,6 +151,15 @@ main() {
print(result.runtimeType);
}
{
// Function with many arguments: arguments get passed in registers and stack.
DecenaryOp sumManyInts = ffiTestFunctions
.lookupFunction<NativeDecenaryOp2, DecenaryOp>("SumManySmallInts");
var result = sumManyInts(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
print(result);
print(result.runtimeType);
}
{
// Function with many double arguments.
DoubleDecenaryOp sumManyDoubles = ffiTestFunctions.lookupFunction<

View file

@ -45,24 +45,40 @@ class Test {
}
typedef SimpleAdditionType = Int32 Function(Int32, Int32);
int simpleAddition(int x, int y) => x + y;
int simpleAddition(int x, int y) {
print("simpleAddition($x, $y)");
return x + y;
}
typedef IntComputationType = Int64 Function(Int8, Int16, Int32, Int64);
int intComputation(int a, int b, int c, int d) => d - c + b - a;
int intComputation(int a, int b, int c, int d) {
print("intComputation($a, $b, $c, $d)");
return d - c + b - a;
}
typedef UintComputationType = Uint64 Function(Uint8, Uint16, Uint32, Uint64);
int uintComputation(int a, int b, int c, int d) => d - c + b - a;
int uintComputation(int a, int b, int c, int d) {
print("uintComputation($a, $b, $c, $d)");
return d - c + b - a;
}
typedef SimpleMultiplyType = Double Function(Double);
double simpleMultiply(double x) => x * 1.337;
double simpleMultiply(double x) {
print("simpleMultiply($x)");
return x * 1.337;
}
typedef SimpleMultiplyFloatType = Float Function(Float);
double simpleMultiplyFloat(double x) => x * 1.337;
double simpleMultiplyFloat(double x) {
print("simpleMultiplyFloat($x)");
return x * 1.337;
}
typedef ManyIntsType = IntPtr Function(IntPtr, IntPtr, IntPtr, IntPtr, IntPtr,
IntPtr, IntPtr, IntPtr, IntPtr, IntPtr);
int manyInts(
int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
print("manyInts($a, $b, $c, $d, $e, $f, $g, $h, $i, $j");
return a + b + c + d + e + f + g + h + i + j;
}
@ -70,6 +86,7 @@ typedef ManyDoublesType = Double Function(Double, Double, Double, Double,
Double, Double, Double, Double, Double, Double);
double manyDoubles(double a, double b, double c, double d, double e, double f,
double g, double h, double i, double j) {
print("manyDoubles($a, $b, $c, $d, $e, $f, $g, $h, $i, $j");
return a + b + c + d + e + f + g + h + i + j;
}
@ -115,6 +132,8 @@ double manyArgs(
double _18,
int _19,
double _20) {
print("manyArgs( $_1, $_2, $_3, $_4, $_5, $_6, $_7, $_8, $_9, $_10," +
"$_11, $_12, $_13, $_14, $_15, $_16, $_17, $_18, $_19, $_20)");
return _1 +
_2 +
_3 +

View file

@ -33,6 +33,7 @@ void main() {
testNativeFunctionManyArguments2();
testNativeFunctionManyArguments3();
testNativeFunctionManyArguments4();
testNativeFunctionManyArguments5();
testNativeFunctionPointer();
testNullInt();
testNullDouble();
@ -229,6 +230,8 @@ void testNativeFunctionFloats() {
typedef NativeDecenaryOp = IntPtr Function(IntPtr, IntPtr, IntPtr, IntPtr,
IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr);
typedef NativeDecenaryOp2 = Int16 Function(
Int8, Int16, Int8, Int16, Int8, Int16, Int8, Int16, Int8, Int16);
typedef DecenaryOp = int Function(
int, int, int, int, int, int, int, int, int, int);
@ -239,6 +242,13 @@ void testNativeFunctionManyArguments1() {
Expect.equals(55, sumManyInts(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
}
DecenaryOp sumManySmallInts = ffiTestFunctions
.lookupFunction<NativeDecenaryOp2, DecenaryOp>("SumManySmallInts");
void testNativeFunctionManyArguments5() {
Expect.equals(55, sumManySmallInts(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
}
typedef NativeUndenaryOp = IntPtr Function(IntPtr, IntPtr, IntPtr, IntPtr,
IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr, IntPtr);
typedef UndenaryOp = int Function(