llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Miscompile when short overlaps 128 byte boundray in class

Open mateoconlechuga opened this issue 2 years ago • 0 comments

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.

mateoconlechuga avatar Nov 21 '23 06:11 mateoconlechuga