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

Chibuoyim Ogbonna via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 06:02:45 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;
----------------
bruteforceboy wrote:

nit: could use `auto` here

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


More information about the cfe-commits mailing list