================
@@ -901,6 +901,33 @@ void
CIRGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &args) {
assert(!cir::MissingFeatures::incrementProfileCounter());
assert(!cir::MissingFeatures::runCleanupsScope());
+ // For a memcpy-equivalent special member (a union, or a trivially-copyable
+ // record) the synthesized body either copies nothing -- a union body is just
+ // `return *this` -- or relies on a memcpy the AST does not spell out as
+ // field assignments. Mirror classic CodeGen's AssignmentMemcpyizer: copy
+ // the whole object once, then fall through to emit the trailing
+ // `return *this`. Emitting the copy but skipping the return would leave the
+ // result reference uninitialized.
+ if (assignOp->isMemcpyEquivalentSpecialMember(getContext())) {
+ CanQualType recordTy =
+ getContext().getCanonicalTagType(assignOp->getParent());
+ LValue dest = makeNaturalAlignAddrLValue(loadCXXThis(), recordTy);
+ // The source is the trailing reference parameter; load it to get the
+ // referent's address before copying (mirrors the copy-constructor path).
+ mlir::Value srcPtr = builder.createLoad(getLoc(assignOp->getLocation()),
+ getAddrOfLocalVar(args.back()));
+ LValue src = makeNaturalAlignAddrLValue(srcPtr, recordTy);
+ emitAggregateAssign(dest, src, recordTy);
+
+ for (Stmt *s : rootCS->body())
+ if (isa<ReturnStmt>(s))
+ if (emitStmt(s, /*useCurrentScope=*/true).failed())
+ cgm.errorNYI(s->getSourceRange(),
+ std::string("emitImplicitAssignmentOperatorBody: ") +
+ s->getStmtClassName());
----------------
andykaylor wrote:
This is really quite concerning. It looks like the AST is currently generating
a compound statement containing nothing but a return statement (at least for
the test case you're adding here), but this is just blindly looking for a
return statement and throwing away anything else that happens to be here. I'd
feel much better about this if it at least asserted on anything that wasn't a
return statement.
https://github.com/llvm/llvm-project/pull/198918
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits