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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 26 12:40:01 UTC 2022


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

--- Comment #11 from Dennis <dkorpel at live.nl> ---
(In reply to Walter Bright from comment #8)
> Increasing the alignment has some problems:

Those problems describe the situation where you increase the assumed alignment
for all functions to a single larger constant, but that's not what I'm saying.

The thing is, this issue has already been mostly fixed by Suleyman Sahmi, but
the bot didn't close this issue when the PR was merged in 2019:

https://github.com/dlang/dmd/pull/9143

The algorithm is this:

Find the maximum alignment by iterating over the types of all local variables
in the function. If it's larger than the minimum stack alignment guaranteed by
the platform, generate code in the function prolog to align the stack to the
required alignment.

For example:
```
struct S { align(128) int i; }

void f()
{
    S x;
}
```
Generates:
```
void onlineapp.f():
        push    RBP
        mov     RBP,RSP
        and     RSP,0FFFFFF80h // < alignment of stack pointer to multiple of
128
        sub     RSP,080h

```

The limitations are this:
- It's only enabled for 64-bit builds and OSX (`&& (I64 || config.exe ==
EX_OSX)`)
- It only looks at variable types, so an `align(128) int x;` is still assumed
to have alignment 4

--


More information about the Digitalmars-d-bugs mailing list