www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20154] New: bad closure if local variables have larger


          Issue ID: 20154
           Summary: bad closure if local variables have larger alignment
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

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


void main()

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.

Aug 23 2019