-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[CIR] Upstream handling of integral-to-pointer casts #161653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
eec6869
54e154c
2807388
d328d27
ec1ca90
2b3d7cb
9a9e05d
119873c
c321248
5866289
728ec84
142e70f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add LLVM checks here? |
||
|
||
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> | ||
Comment on lines
+154
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks need to be expanded. The CIR generated should look like this:
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):
Note that I've used Nothing specific to casts is being lowered to LLVM IR, so I don't think LLVM checks are needed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of these headers needed for your change?
https://llvm.org/docs/CodingStandards.html#include-as-little-as-possible