[Issue 24184] [REG 2.103] Segmentation fault accessing variable with align(N) > platform stack alignment

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 15 09:06:01 UTC 2023


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #3 from Walter Bright <bugzilla at digitalmars.com> ---
I've boiled this down to:

  ubyte[] text() {
    void xxx() { }

    return single!(xxx)(null);
  }

  ubyte[] single(alias xxx)(ubyte[] table) {
    align(64) ubyte[] vector;

    ubyte[] abc() { return vector; }

    stage!(abc)();

    return table;
  }

  void stage(alias abc)() {
    abc();
  }

which compiles to:

  text:
                push    RBP
                mov     RBP,RSP
                xor     ESI,ESI
                xor     EDX,EDX
                xor     EDI,EDI         // context pointer for xxx
                call    single
                pop     RBP
                ret

  xxx:
                ret

  single:
                push    RBP
                mov     RBP,RSP
                sub     RSP,0B0h
                mov     -020h[RBP],RDI
                mov     -010h[RBP],RSI
                mov     -8[RBP],RDX
                lea     RAX,-031h[RBP]
                and     EAX,0FFFFFFC0h
                mov     0FFFFFF50h[RBP],RAX
                mov     RCX,0FFFFFF50h[RBP]
                mov     qword ptr [RCX],0
                mov     qword ptr 8[RCX],0
                lea     RDI,-020h[RBP]      // context pointer for xxx, not
single
                call    stage
                mov     RDX,-8[RBP]
                mov     RAX,-010h[RBP]
                leave
                ret

  abc:
                push    RBP
                mov     RBP,RSP
                sub     RSP,010h
                mov     -8[RBP],RDI
                mov     RAX,0FFFFFF50h[RDI]
                mov     RDX,8[RAX]
                mov     RAX,[RAX]
                leave
                ret

  stage:
                push    RBP
                mov     RBP,RSP
                sub     RSP,010h
                mov     -8[RBP],RDI
                call    abc
                leave
                ret

The error is in the LEA, which loads RDI with the context pointer for xxx(),
when it should be initializing RDI with RBP, the context pointer for single().

--


More information about the Digitalmars-d-bugs mailing list