[clang] [CIR] Correct array-subscript-ordering (PR #227899)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 06:40:18 PDT 2026


================
@@ -1383,11 +1383,16 @@ CIRGenFunction::emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e) {
 
   // The index must always be an integer, which is not an aggregate.  Emit it
   // in lexical order (this complexity is, sadly, required by C++17).
-  assert((e->getIdx() == e->getLHS() || e->getIdx() == e->getRHS()) &&
-         "index was neither LHS nor RHS");
-
-  auto emitIdxAfterBase = [&](bool promote) -> mlir::Value {
-    mlir::Value idx = emitScalarExpr(e->getIdx());
+  mlir::Value idxPre = (e->getLHS() == e->getIdx())
+                           ? emitScalarExpr(e->getIdx())
+                           : mlir::Value();
+
+  auto emitIdxAfterBase = [&, idxPre](bool promote) -> mlir::Value {
+    mlir::Value idx = idxPre;
----------------
erichkeane wrote:

This is a place we cannot use auto actually, `auto` is only for cases where the type is 'obvious' on the right side.  

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


More information about the cfe-commits mailing list