Bug 20154 – bad closure if local variables have larger alignment requirements

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2019-08-23T09:35:35Z
Last change time
2024-12-13T19:05:08Z
Keywords
backend, wrong-code
Assigned to
No Owner
Creator
Rainer Schuetze
Moved to GitHub: dmd#17920 →

Comments

Comment #0 by r.sagitario — 2019-08-23T09:35:35Z
If a local variable has larger alignment requirements, closures that capture function arguments can fail: struct SpinLock { align(64) int x; } void collectReferences(int x) //ref HashTab references) { SpinLock lock; // dmd BUG: alignment causes bad capture! void mark() scope nothrow { assert (x == 7); } mark(); } void main() { collectReferences(7); } For Win64, RSP is aligned according to alignof(SpinLock) for alignments 32-128. This makes the closure offset for the function argument x non-constant. Side note: no alignment happens for align(256) or higher. For Win32, alignment is silently omitted.
Comment #1 by bugzilla — 2020-08-09T03:35:55Z
The alignment code is emitted for Win64, but not for Win32. But you listed the bug applying to x86_64. So please clarify: Is this working for 64 bit platforms?
Comment #2 by bugzilla — 2020-08-09T03:42:43Z
Currently, stack alignment is enforced only for 64 bit compilations and 32 bit OSX compilations. See the setting of `enforcealign` in codgen() in cgcod.d.
Comment #3 by bugzilla — 2020-08-09T04:17:41Z
A somewhat more illustrative test: struct SpinLock { align(64) int x; } void collectReferences(int x) //ref HashTab references) { SpinLock lock = SpinLock(8); // dmd BUG: alignment causes bad capture! void mark() scope nothrow { assert(lock.x == 8); assert(x == 7); } mark(); } void main() { collectReferences(7); }
Comment #4 by r.sagitario — 2020-08-09T05:53:25Z
(In reply to Walter Bright from comment #1) > The alignment code is emitted for Win64, but not for Win32. But you listed > the bug applying to x86_64. Win32 passes the assert, but ignores alignments. > > So please clarify: > > Is this working for 64 bit platforms? No.
Comment #5 by bugzilla — 2020-08-09T07:09:35Z
Thanks, I think I understand it now. But the solution isn't obvious :-/
Comment #6 by robert.schadek — 2024-12-13T19:05:08Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17920 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB