Skip to content

Commit 957487b

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[test/ffi] Structs by value 1-byte aligned
The 3 and 7 byte tests in https://dart-review.googlesource.com/c/sdk/+/168829 had their sizes rounded up to the next power of two due to alignment of fields inside the structs. In order to properly exercise behavior on win32, win64 and iOS, this CL changes those structs to only have uint8 fields to prevent alignment influencing the sizes. Old tests are renamed to exercise the size rounding due to alignment. This also swaps around the two 9byte structs to have consistent naming with the new 3 and 7-byte tests. structs_by_value_tests_confguration.dart is the only non-generated file. The tests are tested in the dependent CL. Tests are ignored in status file and are un-ignored in dependent CL. Tests for #36730. Change-Id: If47cfcaebe56f43d50265f0d6e2749c56fe7b195 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169101 Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Tess Strickland <[email protected]> Reviewed-by: Martin Kustermann <[email protected]>
1 parent dd3642b commit 957487b

9 files changed

+4381
-1911
lines changed

runtime/bin/ffi_test/ffi_test_functions_generated.cc

Lines changed: 1053 additions & 353 deletions
Large diffs are not rendered by default.

tests/ffi/function_callbacks_structs_by_value_generated_test.dart

Lines changed: 1019 additions & 524 deletions
Large diffs are not rendered by default.

tests/ffi/function_structs_by_value_generated_test.dart

Lines changed: 607 additions & 246 deletions
Large diffs are not rendered by default.

tests/ffi/generator/structs_by_value_tests_confguration.dart renamed to tests/ffi/generator/structs_by_value_tests_configuration.dart

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ Smallest struct with data.
1010
10 struct arguments will exhaust available registers."""),
1111
FunctionType(List.filled(10, struct3bytesInt), int64, """
1212
Not a multiple of word size, not a power of two.
13+
10 struct arguments will exhaust available registers."""),
14+
FunctionType(List.filled(10, struct3bytesInt2), int64, """
15+
Not a multiple of word size, not a power of two.
16+
With alignment rules taken into account size is 4 bytes.
1317
10 struct arguments will exhaust available registers."""),
1418
FunctionType(List.filled(10, struct4bytesInt), int64, """
1519
Exactly word size on 32-bit architectures.
1620
10 struct arguments will exhaust available registers."""),
1721
FunctionType(List.filled(10, struct7bytesInt), int64, """
1822
Sub word size on 64 bit architectures.
23+
10 struct arguments will exhaust available registers."""),
24+
FunctionType(List.filled(10, struct7bytesInt2), int64, """
25+
Sub word size on 64 bit architectures.
26+
With alignment rules taken into account size is 8 bytes.
1927
10 struct arguments will exhaust available registers."""),
2028
FunctionType(List.filled(10, struct8bytesInt), int64, """
2129
Exactly word size struct on 64bit architectures.
@@ -29,12 +37,13 @@ On x64, arguments go in int registers because it is not only float.
2937
FunctionType(List.filled(10, struct9bytesInt), int64, """
3038
Argument is a single byte over a multiple of word size.
3139
10 struct arguments will exhaust available registers.
40+
Struct only has 1-byte aligned fields to test struct alignment itself.
3241
Tests upper bytes in the integer registers that are partly filled.
3342
Tests stack alignment of non word size stack arguments."""),
3443
FunctionType(List.filled(10, struct9bytesInt2), int64, """
3544
Argument is a single byte over a multiple of word size.
45+
With alignment rules taken into account size is 12 or 16 bytes.
3646
10 struct arguments will exhaust available registers.
37-
Struct only has 1-byte aligned fields to test struct alignment itself.
3847
"""),
3948
FunctionType(List.filled(6, struct12bytesFloat), float, """
4049
Arguments in FPU registers on arm hardfp and arm64.
@@ -198,23 +207,29 @@ Test alignment and padding of 64 byte int within struct."""),
198207
Smallest struct with data."""),
199208
FunctionType(struct3bytesInt.memberTypes, struct3bytesInt, """
200209
Smaller than word size return value on all architectures."""),
210+
FunctionType(struct3bytesInt2.memberTypes, struct3bytesInt2, """
211+
Smaller than word size return value on all architectures.
212+
With alignment rules taken into account size is 4 bytes."""),
201213
FunctionType(struct4bytesInt.memberTypes, struct4bytesInt, """
202214
Word size return value on 32 bit architectures.."""),
203215
FunctionType(struct7bytesInt.memberTypes, struct7bytesInt, """
204216
Non-wordsize return value."""),
217+
FunctionType(struct7bytesInt2.memberTypes, struct7bytesInt2, """
218+
Non-wordsize return value.
219+
With alignment rules taken into account size is 8 bytes."""),
205220
FunctionType(struct8bytesInt.memberTypes, struct8bytesInt, """
206221
Return value in integer registers on many architectures."""),
207222
FunctionType(struct8bytesFloat.memberTypes, struct8bytesFloat, """
208223
Return value in FP registers on many architectures."""),
209224
FunctionType(struct8BytesMixed.memberTypes, struct8BytesMixed, """
210225
Return value split over FP and integer register in x64."""),
211226
FunctionType(struct9bytesInt.memberTypes, struct9bytesInt, """
212-
Return value in two integer registers on x64.
213-
The second register only contains a single byte."""),
214-
FunctionType(struct9bytesInt2.memberTypes, struct9bytesInt2, """
215227
The minimum alignment of this struct is only 1 byte based on its fields.
216228
Test that the memory backing these structs is the right size and that
217229
dart:ffi trampolines do not write outside this size."""),
230+
FunctionType(struct9bytesInt2.memberTypes, struct9bytesInt2, """
231+
Return value in two integer registers on x64.
232+
With alignment rules taken into account size is 12 or 16 bytes."""),
218233
FunctionType(struct12bytesFloat.memberTypes, struct12bytesFloat, """
219234
Return value in FPU registers, but does not use all registers on arm hardfp
220235
and arm64."""),
@@ -297,8 +312,10 @@ final structs = [
297312
struct0bytes,
298313
struct1byteInt,
299314
struct3bytesInt,
315+
struct3bytesInt2,
300316
struct4bytesInt,
301317
struct7bytesInt,
318+
struct7bytesInt2,
302319
struct8bytesInt,
303320
struct8bytesFloat,
304321
struct8BytesMixed,
@@ -324,14 +341,18 @@ final structs = [
324341
final struct0bytes = StructType([]);
325342

326343
final struct1byteInt = StructType([int8]);
327-
final struct3bytesInt = StructType([int16, int8]);
344+
final struct3bytesInt = StructType(List.filled(3, uint8));
345+
final struct3bytesInt2 = StructType.disambiguate([int16, int8], "2ByteAligned");
328346
final struct4bytesInt = StructType([int16, int16]);
329-
final struct7bytesInt = StructType([int32, int16, int8]);
347+
final struct7bytesInt = StructType(List.filled(7, uint8));
348+
final struct7bytesInt2 =
349+
StructType.disambiguate([int32, int16, int8], "4ByteAligned");
330350
final struct8bytesInt = StructType([int16, int16, int32]);
331351
final struct8bytesFloat = StructType([float, float]);
332352
final struct8BytesMixed = StructType([float, int16, int16]);
333-
final struct9bytesInt = StructType([int64, int8]);
334-
final struct9bytesInt2 = StructType.disambiguate(List.filled(9, uint8), "2");
353+
final struct9bytesInt = StructType(List.filled(9, uint8));
354+
final struct9bytesInt2 =
355+
StructType.disambiguate([int64, int8], "4Or8ByteAligned");
335356
final struct12bytesFloat = StructType([float, float, float]);
336357

337358
/// The largest homogenous float that goes into FPU registers on softfp and

tests/ffi/generator/structs_by_value_tests_generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'dart:io';
66

77
import 'c_types.dart';
8-
import 'structs_by_value_tests_confguration.dart';
8+
import 'structs_by_value_tests_configuration.dart';
99
import 'utils.dart';
1010

1111
/// The test type determines how to convert the arguments into return values

0 commit comments

Comments
 (0)