================
@@ -131,3 +131,25 @@ void bitcast() {
// LLVM: %[[D_VEC:.*]] = load <2 x double>, ptr {{.*}}, align 16
// LLVM: %[[I_VEC:.*]] = bitcast <2 x double> %[[D_VEC]] to <4 x i32>
+
+void f(long int start) {
+ void *p = (void*)start;
+}
+// CIR: %[[L:.*]] = cir.load {{.*}} : !cir.ptr<!s64i>, !s64i
+// CIR: %[[MID:.*]] = cir.cast integral %[[L]] : !s64i -> !u64i
+// CIR: cir.cast int_to_ptr %[[MID]] : !u64i -> !cir.ptr<!void>
+
+struct A { int x; };
+
+void int_cast(long ptr) {
+ ((A *)ptr)->x = 0;
+}
+// CIR: cir.cast int_to_ptr {{.*}} : !u64i -> !cir.ptr<!rec_A>
+// LLVM: inttoptr {{.*}} to ptr
+
+void null_cast(long) {
+ *(int *)0 = 0;
+ ((A *)0)->x = 0;
+}
+// CIR: #cir.ptr<null> : !cir.ptr<!s32i>
+// CIR: #cir.ptr<null> : !cir.ptr<!rec_A>
----------------
andykaylor wrote:
These checks need to be expanded. The CIR generated should look like this:
```
%1 = cir.const #cir.int<0> : !s32i
%2 = cir.const #cir.ptr<null> : !cir.ptr<!s32i>
cir.store align(4) %1, %2 : !s32i, !cir.ptr<!s32i>
%3 = cir.const #cir.int<0> : !s32i
%4 = cir.const #cir.ptr<null> : !cir.ptr<!rec_A>
%5 = cir.get_member %4[0] {name = "x"} : !cir.ptr<!rec_A> -> !cir.ptr<!s32i>
cir.store align(4) %3, %5 : !s32i, !cir.ptr<!s32i>
```
The point of the test is to verify that we're using a null pointer in the
expected instructions, so I'd check at least that (and always use regex
substitutions for SSA values):
```
// CIR: %[[NULLPTR:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!s32i>
// CIR: cir.store{{.*}} %{{.*}}, %[[NULLPTR]] : !s32i, !cir.ptr<!s32i>
// CIR: %[[NULLPTR_A:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!rec_A>
// CIR: %[[A_X:.*]] = cir.get_member %[[NULLPTR_A]][0] {name = "x"} :
!cir.ptr<!rec_A> -> !cir.ptr<!s32i>
```
Note that I've used `%{{.*}}` for the value being stored in the second line,
because we don't need to test that here. Also note, I used `{{.*}}` following
`cir.store` so that this test will pass with or without an alignment specifier,
because that's not relevant to this test and we wouldn't want to have to update
this test if alignment behavior is changed in the future.
Nothing specific to casts is being lowered to LLVM IR, so I don't think LLVM
checks are needed here.
https://github.com/llvm/llvm-project/pull/161653
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits