[clang] [CIR] Upstream pointer arithmetic support (PR #138041)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 30 15:54:33 PDT 2025


================
@@ -1152,8 +1169,72 @@ getUnwidenedIntegerType(const ASTContext &astContext, const Expr *e) {
 static mlir::Value emitPointerArithmetic(CIRGenFunction &cgf,
                                          const BinOpInfo &op,
                                          bool isSubtraction) {
-  cgf.cgm.errorNYI(op.loc, "pointer arithmetic");
-  return {};
+  // Must have binary (not unary) expr here.  Unary pointer
+  // increment/decrement doesn't use this path.
+  const BinaryOperator *expr = cast<BinaryOperator>(op.e);
+
+  mlir::Value pointer = op.lhs;
+  Expr *pointerOperand = expr->getLHS();
+  mlir::Value index = op.rhs;
----------------
erichkeane wrote:

Calling this 'index' is suspicious, since `pointer - pointer` is valid.

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


More information about the cfe-commits mailing list