-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overlapping field initialization in CTFE-generated union literal #20675
Comments
Works around issue seen in dlang/dmd#20675.
Works around issue seen in dlang/dmd#20675.
Works around issue seen in dlang/dmd#20675.
In dmd/compiler/src/dmd/dinterpret.d Lines 3871 to 3872 in a4cbc08
u.s was a union, setting u.s.l would stomp all existing initializers for other u.s members. But this code doesn't take into account that there might be overlaps with parent fields (u.i here).
In v2.111.0-beta.1, we end up with overlapping initializers for |
Another testcase from ldc-developers/ldc#4374, again by setting a union member indirectly/partially by setting a member of that member: union U {
int x;
int[1] arr;
}
U make() {
U u;
u.arr[0] = 123;
return u;
}
void main()
{
enum u = make(); // overlapping initializers: `U(0, [123])`
auto r = u;
} |
To work around dlang/dmd#20675.
…10683) To work around dlang/dmd#20675.
Reduced from dlang/phobos#9064
Assert fails because what CTFE generates is:
And dmd backend codegen for static initializers ignores overlapping fields, resulting in the value becoming
U(0)
, while the runtime initializer sets each field individually asb.i = 0; b.s.l = 1;
.Workaround is to declare variable as being void initialized.
This results in the correct value being generated.
The text was updated successfully, but these errors were encountered: