[clang] [CIR] Coerce record returns from memory like CreateCoercedLoad (PR #227482)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 29 15:52:33 PDT 2026


================
@@ -295,6 +295,87 @@ static uint64_t coercionByteSize(mlir::Type ty, const mlir::DataLayout &dl) {
   return dl.getTypeSize(ty);
 }
 
+/// \p ty's size rounded up to its ABI alignment.
+static uint64_t getAllocSize(mlir::Type ty, const mlir::DataLayout &dl) {
+  return llvm::alignTo(dl.getTypeSize(ty), dl.getTypeABIAlignment(ty));
+}
+
+/// A \p wantTy-typed view of the storage \p base points at.  When \p wantTy is
+/// \p base's own pointee type, \p base is returned unchanged and \p offset is
+/// ignored.  Any other type is reached by a bitcast, preceded by a byte stride
+/// of \p offset bytes when \p offset is nonzero.  The view keeps \p base's
+/// address space.  Any operations created are added to \p createdOps.
+static mlir::Value
+emitViewAtOffset(mlir::OpBuilder &builder, mlir::Location loc,
+                 mlir::Type wantTy, mlir::Value base,
+                 SmallPtrSetImpl<mlir::Operation *> &createdOps,
+                 unsigned offset) {
+  auto basePtrTy = mlir::cast<cir::PointerType>(base.getType());
+  if (wantTy == basePtrTy.getPointee())
----------------
andykaylor wrote:

Can we assert that `offset` is zero in this case?

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


More information about the cfe-commits mailing list