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

Make it easier to define descriptor() when alignment > 8 #51

Open
EvanKirshenbaum opened this issue Sep 28, 2017 · 0 comments
Open

Make it easier to define descriptor() when alignment > 8 #51

EvanKirshenbaum opened this issue Sep 28, 2017 · 0 comments

Comments

@EvanKirshenbaum
Copy link
Collaborator

[imported from HPE issue 322]

When a GC-allocated or GC-friendly class has alignment greater than 8, the gc_descriptor rule that says that every word must be mentioned in the descriptor() function causes problems, because there may be words before fields and at the end of the record that aren't namable.

Currently, the workaround is to add extra explicit padding fields, as in

struct alignas(16) big {
  size_t low = 0;
  size_t high = 0;
};

struct alsoBig : gc_allocated {
  size_t _pad;
  big _big;
  bool _b = false;
  size_t _pad2;
};

Ideally, we could come up with a way to have the checking logic pay attention to the alignment of the field types and figure out when there is necessarily padding. As a short-term solution, we could add a couple more macros to allow the descriptor to be specified as something like

  static const auto &descriptor() {
    using this_type = alsoBig;
    static gc_descriptor d =
      GC_DESC(this_type)
      .pad(1)
      .template WITH_FIELD(&this_type::_big)
      .template WITH_FIELD(&this_type::_b)
      .pad(1)
      ;
    return d;
  }

with the notion being that n words of padding are marked before the next mentioned field or, if there is no following field, at the end of the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant