Skip to content

Represent all assignment operator calls in the IR #1177

Open
@smeenai

Description

@smeenai

ClangIR tries to represent all function calls in the IR (e.g. CodeGen omits calls to trivial constructors but CIRGen keeps them). One exception I've discovered is around calling operator= for an array member when generating a default operator=. https://godbolt.org/z/nEE46ff9d is an example; for the following code:

struct S { int i; };
struct T {
    S arr[4];
    T &operator=(const T &);
};
T &T::operator=(const T &) = default;

The generated code for T::operator= does a memcpy for the arr field instead of emitting the individual S::operator= calls for each array member.

This stems from how CIRGen (and CodeGen) generate default assignment operators. Clang generates an AST representation of the assignment operator, which already contains a __builtin_memcpy call for the arr field, and then CIRGen emits code for that AST. We'd need to change the AST itself to not generate a memcpy here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IR designConsiderations around the design of ClangIR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions