[clang] [CIR] Use data size in emitAggregateCopy for overlapping copies (PR #186702)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 4 14:36:55 PDT 2026


================
@@ -1244,16 +1244,26 @@ void CIRGenFunction::emitAggregateCopy(LValue dest, LValue src, QualType ty,
 
   assert(!cir::MissingFeatures::aggValueSlotVolatile());
 
-  // NOTE(cir): original codegen would normally convert destPtr and srcPtr to
-  // i8* since memcpy operates on bytes. We don't need that in CIR because
-  // cir.copy will operate on any CIR pointer that points to a sized type.
-
   // Don't do any of the memmove_collectable tests if GC isn't set.
   if (cgm.getLangOpts().getGC() != LangOptions::NonGC)
     cgm.errorNYI("emitAggregateCopy: GC");
 
-  [[maybe_unused]] cir::CopyOp copyOp =
-      builder.createCopy(destPtr.getPointer(), srcPtr.getPointer(), isVolatile);
+  // If the data size (excluding tail padding) differs from the full type size,
+  // we can't use cir.copy (which always copies the full pointee type). Instead,
----------------
erichkeane wrote:

This is a 'WHY' to me?  Can we teach `cir.copy` instead to know it can skip tail padding?  It would be great if we just had `cir.copy` have an additional 'tail padding' field or something, so that it knew what to skip.

https://github.com/llvm/llvm-project/pull/186702


More information about the cfe-commits mailing list