There's a failing unittest on ARM in rt.aaA. The test uses a struct without any non-fields as an index for the AA. The hashing function for an empty struct always hashes exactly one byte. It seems this data is not always copied when assigning an empty struct. It probably requires the values to be passed on the stack. void foo() { int a; } struct NoField { //ubyte f; } void main() { foo(); NoField[2] fields = void; fields[0] = NoField(); import core.stdc.stdio; printf("%d\n", *(cast(ubyte*)&fields[0])); }
I tried adding a fake 1 ubyte field to such types, but this messes up interfacing with C/C++ ABIs for empty structs. Is there any oher way to force the backend to actually intialize/copy the data in a struct variable?
The spec doesn't guarantee any consistent hashing for empty structs. Fix for the druntime test: https://github.com/D-Programming-GDC/GDC/commit/4191dbfbc70327a69490c6da717523eb330f39d9
Strictly speaking, field-less structs aren't copied around in our codegen for GCC anyway (there's nothing to copy). Empty variables aren't passed, a new empty constructor is generated instead. This is what the backend expects to see also.