[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:37 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.
----------------
andykaylor wrote:

What happened to the call to EmitIdxAfterBase()? It looks like you've simplified the code here (and in the earlier implementation), but I'm not sure we don't need some of what has been eliminated. At least when we add support for sanitizers we'll want the bounds check in emitIdxAfterBase.

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


More information about the cfe-commits mailing list