Skip to content

Commit bfcc6a8

Browse files
committed
[CIR] Backport ArraySubscript for ComplexType
1 parent 33c739f commit bfcc6a8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
108108
mlir::Value VisitObjCMessageExpr(ObjCMessageExpr *E) {
109109
llvm_unreachable("NYI");
110110
}
111-
mlir::Value VisitArraySubscriptExpr(Expr *E) { llvm_unreachable("NYI"); }
111+
mlir::Value VisitArraySubscriptExpr(Expr *E) { return emitLoadOfLValue(E); }
112112
mlir::Value VisitMemberExpr(MemberExpr *ME) { llvm_unreachable("NYI"); }
113113
mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *E) {
114114
llvm_unreachable("NYI");

clang/test/CIR/CodeGen/complex.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,23 @@ int extract_imag_and_add(int _Complex a, int _Complex b) {
398398
void complex_with_empty_init() { int _Complex c = {}; }
399399

400400
// CHECK: {{.*}} = cir.const #cir.complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i>
401+
402+
void complex_array_subscript() {
403+
int _Complex arr[2];
404+
int _Complex r = arr[1];
405+
}
406+
407+
// CHECK: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 2>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 2>>, ["arr"]
408+
// CHECK: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["r", init]
409+
// CHECK: %[[IDX:.*]] = cir.const #cir.int<1> : !s32i
410+
// CHECK: %[[ARR_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : !cir.ptr<!cir.array<!cir.complex<!s32i> x 2>>), !cir.ptr<!cir.complex<!s32i>>
411+
// CHECK: %[[RESULT_VAL:.*]] = cir.ptr_stride(%[[ARR_PTR]] : !cir.ptr<!cir.complex<!s32i>>, %[[IDX]] : !s32i), !cir.ptr<!cir.complex<!s32i>>
412+
// CHECK: %[[TMP:.*]] = cir.load{{.*}} %[[RESULT_VAL]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
413+
// CHECK: cir.store{{.*}} %[[TMP]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
414+
415+
// LLVM: %[[ARR:.*]] = alloca [2 x { i32, i32 }], i64 1, align 16
416+
// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
417+
// LLVM: %[[ARR_PTR:.*]] = getelementptr { i32, i32 }, ptr %[[ARR]], i32 0
418+
// LLVM: %[[RESULT_VAL:.*]] = getelementptr { i32, i32 }, ptr %[[ARR_PTR]], i64 1
419+
// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[RESULT_VAL]], align 8
420+
// LLVM: store { i32, i32 } %[[TMP]], ptr %[[RESULT]], align 4

0 commit comments

Comments
 (0)