|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR |
| 3 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -emit-mlir %s -o %t.mlir |
| 4 | +// RUN: FileCheck --input-file=%t.mlir %s --check-prefix=MLIR |
| 5 | + |
| 6 | +int test_array1() { |
| 7 | + // CIR-LABEL: cir.func {{.*}} @test_array1 |
| 8 | + // CIR: %[[ARRAY:.*]] = cir.alloca !cir.array<!s32i x 3>, !cir.ptr<!cir.array<!s32i x 3>>, ["a"] {alignment = 4 : i64} |
| 9 | + // CIR: %{{.*}} = cir.cast(array_to_ptrdecay, %[[ARRAY]] : !cir.ptr<!cir.array<!s32i x 3>>), !cir.ptr<!s32i> |
| 10 | + |
| 11 | + // MLIR-LABEL: func @test_array1 |
| 12 | + // MLIR: %{{.*}} = memref.alloca() {alignment = 4 : i64} : memref<i32> |
| 13 | + // MLIR: %[[ARRAY:.*]] = memref.alloca() {alignment = 4 : i64} : memref<3xi32> |
| 14 | + // MLIR: %{{.*}} = memref.load %[[ARRAY]][%{{.*}}] : memref<3xi32> |
| 15 | + int a[3]; |
| 16 | + return a[1]; |
| 17 | +} |
| 18 | + |
| 19 | +int test_array2() { |
| 20 | + // CIR-LABEL: cir.func {{.*}} @test_array2 |
| 21 | + // CIR: %[[ARRAY:.*]] = cir.alloca !cir.array<!cir.array<!s32i x 4> x 3>, !cir.ptr<!cir.array<!cir.array<!s32i x 4> x 3>>, ["a"] {alignment = 16 : i64} |
| 22 | + // CIR: %{{.*}} = cir.cast(array_to_ptrdecay, %[[ARRAY]] : !cir.ptr<!cir.array<!cir.array<!s32i x 4> x 3>>), !cir.ptr<!cir.array<!s32i x 4>> |
| 23 | + // CIR: %{{.*}} = cir.cast(array_to_ptrdecay, %{{.*}} : !cir.ptr<!cir.array<!s32i x 4>>), !cir.ptr<!s32i> |
| 24 | + |
| 25 | + // MLIR-LABEL: func @test_array2 |
| 26 | + // MLIR: %{{.*}} = memref.alloca() {alignment = 4 : i64} : memref<i32> |
| 27 | + // MLIR: %[[ARRAY:.*]] = memref.alloca() {alignment = 16 : i64} : memref<3x4xi32> |
| 28 | + // MLIR: %{{.*}} = memref.load %[[ARRAY]][%{{.*}}, %{{.*}}] : memref<3x4xi32> |
| 29 | + int a[3][4]; |
| 30 | + return a[1][2]; |
| 31 | +} |
0 commit comments