jacobly0 / llvm-project

This fork of the canonical git mirror of the LLVM subversion repository adds (e)Z80 targets. Please refer to the wiki for important build instructions.
https://github.com/jacobly0/llvm-project/wiki
123 stars 15 forks source link

Miscompile when short overlaps 128 byte boundray in class #40

Open mateoconlechuga opened 1 year ago

mateoconlechuga commented 1 year ago

main.cpp

class a {
public:
    a() = default;
};

class b {
private:
    char pad[127];
    short x;

public:
    b() = default;
    a *f()
    {
        (void)pad;
        x = 55;
        return new a;
    }
};

static b c;

int main(void)
{
    c.f();
    return 0;
}

compile result:

    section .text,"ax",@progbits
    assume  adl = 1
    section .text,"ax",@progbits
    public  _main
_main:
    ld  hl, __ZL1c
    push    hl
    call    __ZN1b1fEv
    pop hl
    or  a, a
    sbc hl, hl
    ret
    section .text,"ax",@progbits

    section .text,"ax",@progbits
    weak    __ZN1b1fEv
__ZN1b1fEv:
    call    __frameset0
    ld  iy, (ix + 6)
    ld.sis  hl, 55
    ld  de, 1
    ld  (iy + 127), l
    ld  (iy + 128), h
    ld  (ix + 6), de
    pop ix
    jp  __Znwj
    section .text,"ax",@progbits

    section .bss,"aw",@nobits
    private __ZL1c
__ZL1c:
    rb  129

    ident   "clang version 15.0.0 (https://github.com/jacobly0/llvm-project fcc1b7e50dd53a82c7aa1da469c572fbe23d2b54)"
    extern  __Unwind_SjLj_Register
    extern  __Unwind_SjLj_Unregister
    extern  __frameset0
    extern  __Znwj

there should be no ld (iy + 128), h in the resulting assembly as this is an invalid instruction.