Sema: fix get a incorrect element pointer type for C pointer of array#23506
Closed
flyfish30 wants to merge 2 commits intoziglang:masterfrom
Closed
Sema: fix get a incorrect element pointer type for C pointer of array#23506flyfish30 wants to merge 2 commits intoziglang:masterfrom
flyfish30 wants to merge 2 commits intoziglang:masterfrom
Conversation
bc7b6d8 to
afc83a7
Compare
Contributor
Author
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
Vexu
reviewed
Apr 19, 2025
| 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); |
Member
There was a problem hiding this comment.
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: { |
Member
There was a problem hiding this comment.
Why is there an inner and an outer blk? Did you run into a bug?
Member
|
Feedback left unaddressed for >3 months |
Contributor
Author
Member
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.