[clang] [CIR] Upstream ArraySubscriptExpr from function parameter with pointer base (PR #135493)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 14 10:04:38 PDT 2025


================
@@ -570,9 +570,17 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
   }
 
   // The base must be a pointer; emit it with an estimate of its alignment.
-  cgm.errorNYI(e->getSourceRange(),
-               "emitArraySubscriptExpr: The base must be a pointer");
-  return {};
+  assert(e->getBase()->getType()->isPointerType() &&
+         "The base must be a pointer");
+
+  LValueBaseInfo eltBaseInfo;
+  const Address ptrAddr = emitPointerWithAlignment(e->getBase(), &eltBaseInfo);
+  // Propagate the alignment from the array itself to the result.
+  const Address addxr = emitArraySubscriptPtr(
+      *this, cgm.getLoc(e->getBeginLoc()), cgm.getLoc(e->getEndLoc()), ptrAddr,
+      e->getType(), idx, cgm.getLoc(e->getExprLoc()),
+      /*shouldDecay=*/false);
+  return LValue::makeAddr(addxr, e->getType(), eltBaseInfo);
----------------
andykaylor wrote:

You're missing an errorNYI here for ObjectC garbage collection. This should also happen for the case that returns on line 569 here but falls through in the incubator implementation.

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


More information about the cfe-commits mailing list