Skip to content
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

Union is not properly zero-initialized #1194

Closed
cbuttner opened this issue May 15, 2024 · 5 comments
Closed

Union is not properly zero-initialized #1194

cbuttner opened this issue May 15, 2024 · 5 comments
Assignees
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works

Comments

@cbuttner
Copy link
Contributor

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)
}
@lerno lerno self-assigned this May 16, 2024
@lerno lerno added the Bug Something isn't working label May 16, 2024
@lerno
Copy link
Collaborator

lerno commented May 16, 2024

Ooooh, interesting!

@lerno
Copy link
Collaborator

lerno commented May 16, 2024

I can't reproduce this and the LLVM output looks fine, is there some variant of this that you used?

@cbuttner
Copy link
Contributor Author

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;
}

@lerno lerno added the Fixed Needs Verification Fixed, but needs verification that it works label May 16, 2024
@lerno
Copy link
Collaborator

lerno commented May 16, 2024

Should work fine now.

@cbuttner
Copy link
Contributor Author

cbuttner commented Jun 6, 2024

This fixed it for me, thanks.

@cbuttner cbuttner closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works
Projects
None yet
Development

No branches or pull requests

2 participants