Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscompile when short overlaps 128 byte boundray in class #40

Open
mateoconlechuga opened this issue Nov 21, 2023 · 0 comments
Open

Miscompile when short overlaps 128 byte boundray in class #40

mateoconlechuga opened this issue Nov 21, 2023 · 0 comments

Comments

@mateoconlechuga
Copy link

mateoconlechuga commented Nov 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant