[clang] [CIR] Upstream pointer subtraction handling (PR #163306)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 14 15:34:23 PDT 2025
================
@@ -1499,6 +1499,48 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
return mlir::success();
}
+static uint64_t getTypeSize(mlir::Type type, mlir::Operation &op) {
+ mlir::DataLayout layout(op.getParentOfType<mlir::ModuleOp>());
+ // For LLVM purposes we treat void as u8.
+ if (isa<cir::VoidType>(type))
+ type = cir::IntType::get(type.getContext(), 8, /*isSigned=*/false);
+ return llvm::divideCeil(layout.getTypeSizeInBits(type), 8);
+}
+
+mlir::LogicalResult CIRToLLVMPtrDiffOpLowering::matchAndRewrite(
+ cir::PtrDiffOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ auto dstTy = mlir::cast<cir::IntType>(op.getType());
+ auto llvmDstTy = getTypeConverter()->convertType(dstTy);
----------------
andykaylor wrote:
```suggestion
mlir::Type llvmDstTy = getTypeConverter()->convertType(dstTy);
```
As we upstream code from the incubator, we're generally removing uses of `auto` that don't conform to the LLVM coding standard (which is less liberal than the MLIR coding standard).
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable
https://github.com/llvm/llvm-project/pull/163306
More information about the cfe-commits
mailing list