[Issue 16098] align(N) not respected for stack variables if N > platform stack alignment

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 23 09:14:51 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=16098

--- Comment #6 from Walter Bright <bugzilla at digitalmars.com> ---
One way to fix this is to:

1. gather all the locals with larger alignment and put them as fields in a
struct variable

2. the first field in the struct is enough alignment padding to cover the worst
case alignment bytes needed. For example, if the stack is aligned at 4, and the
alignment of the fields is 16, then this field needs to be 12 bytes in size.

3. create a special pointer variable P that points to the aligned start of the
struct fields, computed at function entry:

    P = (&struct + 15) & ~0xF;  // for 16 byte alignment

4. rewrite all references to the variables in the struct as P->field

5. be careful that it works with closures allocated with the gc

This should be doable all in the glue code, no need to modify the backend.

Of course, this can be done explicitly for the moment, to unblock code.

--


More information about the Digitalmars-d-bugs mailing list