Skip to content

Commit f6fae73

Browse files
committed
Add more tests
1 parent 08d89c1 commit f6fae73

File tree

1 file changed

+56
-0
lines changed
  • clang/test/CIR/CodeGen

1 file changed

+56
-0
lines changed

clang/test/CIR/CodeGen/vla.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,59 @@ int f9(unsigned n, char (*p)[n][n+1][6]) {
9393

9494
return p2 - p;
9595
}
96+
97+
long f10(int n) {
98+
int (*p)[n];
99+
int (*q)[n];
100+
return q - p;
101+
}
102+
// CHECK: cir.func dso_local @f10(%arg0: !s32i
103+
// CHECK: %[[N_ADDR:.*]] = cir.alloca !s32i
104+
// CHECK: %[[RETVAL:.*]] = cir.alloca !s64i
105+
// CHECK: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!s32i>
106+
// CHECK: %[[Q_ADDR:.*]] = cir.alloca !cir.ptr<!s32i>
107+
108+
// CHECK: %[[N:.*]] = cir.load{{.*}} %[[N_ADDR]] : !cir.ptr<!s32i>, !s32i
109+
// CHECK: %[[N_U64:.*]] = cir.cast integral %[[N]] : !s32i -> !u64i
110+
111+
// CHECK: %[[Q:.*]] = cir.load{{.*}} %[[Q_ADDR]]
112+
// CHECK: %[[P:.*]] = cir.load{{.*}} %[[P_ADDR]]
113+
114+
// CHECK: %[[DIFF:.*]] = cir.ptr_diff %[[Q]], %[[P]] : !cir.ptr<!s32i> -> !s64i
115+
116+
// CHECK: %[[N_S64:.*]] = cir.cast integral %[[N_U64]] : !u64i -> !s64i
117+
// CHECK: %[[ELTSIZE:.*]] = cir.const #cir.int<4> : !s64i
118+
// CHECK: %[[DIVISOR:.*]] = cir.binop(mul, %[[ELTSIZE]], %[[N_S64]]) nuw : !s64i
119+
120+
// CHECK: %[[RESULT:.*]] = cir.binop(div, %[[DIFF]], %[[DIVISOR]]) : !s64i
121+
122+
123+
long f11(int n, int m) {
124+
int (*p)[n][m];
125+
int (*q)[n][m];
126+
return q - p;
127+
}
128+
// CHECK: cir.func dso_local @f11(
129+
// CHECK: %[[N_ADDR:.*]] = cir.alloca !s32i
130+
// CHECK: %[[M_ADDR:.*]] = cir.alloca !s32i
131+
// CHECK: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!s32i>
132+
// CHECK: %[[Q_ADDR:.*]] = cir.alloca !cir.ptr<!s32i>
133+
134+
// CHECK: %[[N:.*]] = cir.load{{.*}} %[[N_ADDR]] : !cir.ptr<!s32i>, !s32i
135+
// CHECK: %[[N_U64:.*]] = cir.cast integral %[[N]] : !s32i -> !u64i
136+
137+
// CHECK: %[[M:.*]] = cir.load{{.*}} %[[M_ADDR]] : !cir.ptr<!s32i>, !s32i
138+
// CHECK: %[[M_U64:.*]] = cir.cast integral %[[M]] : !s32i -> !u64i
139+
140+
// CHECK: %[[Q:.*]] = cir.load{{.*}} %[[Q_ADDR]]
141+
// CHECK: %[[P:.*]] = cir.load{{.*}} %[[P_ADDR]]
142+
143+
// CHECK: %[[DIFF:.*]] = cir.ptr_diff %[[Q]], %[[P]] : !cir.ptr<!s32i> -> !s64i
144+
145+
// CHECK: %[[NM_UL:.*]] = cir.binop(mul, %[[N_U64]], %[[M_U64]]) : !u64i
146+
// CHECK: %[[NM:.*]] = cir.cast integral %[[NM_UL]] : !u64i -> !s64i
147+
148+
// CHECK: %[[ELTSIZE:.*]] = cir.const #cir.int<4> : !s64i
149+
// CHECK: %[[TOTALSIZE:.*]] = cir.binop(mul, %[[ELTSIZE]], %[[NM]]) nuw : !s64i
150+
151+
// CHECK: %[[RESULT:.*]] = cir.binop(div, %[[DIFF]], %[[TOTALSIZE]]) : !s64i

0 commit comments

Comments
 (0)