Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1126.96.36.199)
Given a C struct with a trailing member that is a 0-length array*:
Swift cannot produce a valid pointer to the payload field.
I have two helper functions in C to aid inspection (lldb seems to sometimes have trouble recognizing Swift pointer variables):
Then, working with a heap-allocated instance of the struct in Swift:
If the offset/pointer is calculated in C, Swift can use it perfectly well. The problem seems to be solely with Swift's calculation of the location of the field.
The address range is different in a release build (tested with -fno-pie), but the behavior is effectively the same.
Full running example attached, also available at https://github.com/woolsweater/flex-arr-mem , "bug-report" branch (there is a fuller example on master).
*In lieu of a true flexible array member int8_t payload, which isn't imported at all. (Swift does handle a member with declared length 1 correctly, however.)