Skip to content

Trivally copyable class with std::nullptr_t is returned on return slot #113388

@leni536

Description

@leni536

Consider:

#include <cstddef>
#include <type_traits>

struct S {
    std::nullptr_t n;
};

static_assert(std::is_trivially_copyable_v<S>);

S foo() {
    return {};
}

Observed behavior

clang 19.1.0 x86_64 returns on return slot:

foo():
        mov     rax, rdi
        mov     qword ptr [rdi], 0
        ret

In comparison gcc 14.2 returns in register:

foo():
        xor     eax, eax
        ret

https://godbolt.org/z/vaqxYoKTW

Expected behavior

The calling convention on gcc and clang to agree. S is not "non-trivial for the purpose of calls" in the Itanium ABI, therefore it should be returned in registers here.

Note

For std::nullptr_t f() { return {}; } clang correctly returns in a register.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary Interfaceclang:codegenIR generation bugs: mangling, exceptions, etc.duplicateResolved as duplicate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions