[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 11:01:27 PDT 2025


================
@@ -29,8 +29,15 @@ int f[5] = {1, 2};
 
 void func() {
   int arr[10];
-
   // CHECK: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 10>, !cir.ptr<!cir.array<!s32i x 10>>, ["arr"]
+
+  int e = arr[1];
+  // CHECK: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
+  // CHECK: %[[IDX:.*]] = cir.const #cir.int<1> : !s32i
+  // CHECK: %[[ARR_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : !cir.ptr<!cir.array<!s32i x 10>>), !cir.ptr<!s32i>
+  // CHECK: %[[ELE_PTR:.*]] = cir.ptr_stride(%[[ARR_PTR]] : !cir.ptr<!s32i>, %[[IDX]] : !s32i), !cir.ptr<!s32i>
+  // CHECK: %[[TMP:.*]] = cir.load %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i
+  // CHECK" cir.store %[[TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
----------------
bcardosolopes wrote:

> I think eventually we could get rid of all the lowering tests

Even though we don't want encourage people to write `.cir` tests (because they are hard to update, etc) and c/c++ has better end-to-end coverage, we probably still need a place for tests with `.cir` suffix whenever they make sense (handy for testing against niche bugs, regressions and whatever corner case make sense). I'm not particular with the "Lowering" name, but I think it's probably nice if those tests are not directly under `CodeGen`.

> Would it create problems for rebasing the incubator?

I don't think so, @lanza can you confirm?

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


More information about the cfe-commits mailing list