c3c
c3c copied to clipboard
Union is not properly zero-initialized
union Rect {
struct { float[<2>] min, max; }
// More stuff here...
}
fn void main() {
Rect rect = {.max = {1, 2});
assert(rect.min == {}); // Assert will fail: rect.min is not zero (in general)
}
Ooooh, interesting!
I can't reproduce this and the LLVM output looks fine, is there some variant of this that you used?
Ah right, my example was actually working. This is what I tested with:
union Rect {
struct { float[<2>] min, max; }
}
fn void test_rect(float[<2>] max) {
Rect rect = {.max = max};
assert(rect.min == {});
}
fn void main() {
test_rect({1,2});
}
My full union looks like this by the way. I don't think it's required to reproduce the issue, but you can check codegen for this too.
union Rect {
struct { float min_x, min_y, max_x, max_y; }
struct { float left, top, right, bottom; }
struct { Vec2f min, max; }
Vec4f v;
Vec2f[2] p;
}
Should work fine now.
This fixed it for me, thanks.