-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Sema: fix get a incorrect element pointer type for C pointer of array #23506
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
Conversation
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.
Needs a behavior test.
bc7b6d8
to
afc83a7
Compare
I had add a "dereference C pointer of array" test case into behavior test. |
When there has a C pointer of array that type is `[*c][2]c_int`, the sema can not get a correct element pointer type for this C pointer. For example, there is a C pointer `c_ptr: [*c][2]c_int`, the type of `&c_ptr.*[0]` is `*c_int`, but the sema get a incorrect type that is `*[2]c_int`. The root cause is in elemPtrType function, so I made the following modifications to this function: If the array_ptr_orig is a C pointer, and it is to be derefenced, then the pointer is same as the one size zig pointer. So we cast the C pointer to a one size zig pointer.
c3a1b47
to
c85e958
Compare
var ptr_info = array_ptr_ty_orig.ptrInfo(zcu); | ||
const array_ptr, const array_ptr_ty = if (ptr_info.flags.size == .c) blk_outer: { | ||
const array_ptr_orig_inst = array_ptr_orig.toIndex().?; | ||
const air_tags = sema.air_instructions.items(.tag); |
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.
Why are you looking at the instruction instead of the type? Did checking the type not work?
const array_ptr_orig_inst = array_ptr_orig.toIndex().?; | ||
const air_tags = sema.air_instructions.items(.tag); | ||
const array_ptr_tag = air_tags[@intFromEnum(array_ptr_orig_inst)]; | ||
break :blk_outer if (array_ptr_tag == .load) blk_inner: { |
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.
Why is there an inner and an outer blk
? Did you run into a bug?
Feedback left unaddressed for >3 months |
Feedback was submitted by Vexu in April with questions about your implementation / suggested changes, and you never addressed or responded to it. If you are able to resolve that feedback, feel free to re-open the PR. |
fixes #22045
When there has a C pointer of array that type is
[*c][2]c_int
, the sema can not get a correct element pointer type for this C pointer. For example, there is a C pointerc_ptr: [*c][2]c_int
, the type of&c_ptr.*[0]
is*c_int
, but the sema get a incorrect type that is*[2]c_int
.The root cause is in elemPtrType function, so I made the following modifications to this function:
If the array_ptr_orig is a C pointer of array, and it is to be derefenced, then the pointer is same as the one size zig pointer. So we cast the C pointer to a one size zig pointer.