Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 236 - Empty structs not copied correctly
Summary: Empty structs not copied correctly
Status: RESOLVED INVALID
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: ARM All
: --- minor
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2016-08-08 19:18 CEST by Johannes Pfau
Modified: 2016-10-01 13:33 CEST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johannes Pfau 2016-08-08 19:18:22 CEST
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]));
}
Comment 1 Johannes Pfau 2016-08-11 15:12:17 CEST
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?
Comment 2 Johannes Pfau 2016-10-01 08:53:43 CEST
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
Comment 3 Iain Buclaw 2016-10-01 13:33:16 CEST
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.