Skip to content

[Backend][X86] Incorrect output + missed optimization for function marked as clang::musttail #56891

@huangjd

Description

@huangjd

As of commit 4bd9d98

When compiling this source code

struct A {
    int a[5];
};

extern int G(A a);

int F(A a) {
    [[clang::musttail]] return G(a);
}

with -O3 -target x86_64-linux, clang generates the following assembly (only showing relevant part)

_Z1F1A:                                 # @_Z1F1A
	.cfi_startproc
# %bb.0:                                # %entry
	movl	24(%rsp), %eax
	movl	%eax, 16(%rsp)
	movaps	8(%rsp), %xmm0
	movups	%xmm0, (%rsp)
	movaps	%xmm0, 8(%rsp)
	movl	%eax, 24(%rsp)
	jmp	_Z1G1A@PLT                      # TAILCALL
.Lfunc_end0:

movups %xmm0, (%rsp) overwrites the return address of caller F, which will result in a crash.

Metadata

Metadata

Assignees

No one assigned

    Type

    No fields configured for Bug.

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions