Description
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.