| author | |
| committer | |
| log | 069fc1a26990b3946cf788b4ebe5edefca5a3bfd |
| tree | bc9c44ef542d629ad3d2cb15c085ea7c4827a830 |
| parent | 57a7ab0d330416f15c0288004b67101c1c3e9629 |
| signature | Commit is signed but in an unrecognized format. |
See #10592 files changed, 33 insertions(+), 0 deletions(-)
src/ir.cpp+18| ... | ... | @@ -9275,6 +9275,24 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9275 | 9275 | continue; |
| 9276 | 9276 | } |
| 9277 | 9277 | |
| 9278 | if (prev_type->id == ZigTypeIdPointer && cur_type->id == ZigTypeIdPointer) { | |
| 9279 | if (prev_type->data.pointer.ptr_len == PtrLenC && | |
| 9280 | types_match_const_cast_only(ira, prev_type->data.pointer.child_type, | |
| 9281 | cur_type->data.pointer.child_type, source_node, | |
| 9282 | !prev_type->data.pointer.is_const).id == ConstCastResultIdOk) | |
| 9283 | { | |
| 9284 | continue; | |
| 9285 | } | |
| 9286 | if (cur_type->data.pointer.ptr_len == PtrLenC && | |
| 9287 | types_match_const_cast_only(ira, cur_type->data.pointer.child_type, | |
| 9288 | prev_type->data.pointer.child_type, source_node, | |
| 9289 | !cur_type->data.pointer.is_const).id == ConstCastResultIdOk) | |
| 9290 | { | |
| 9291 | prev_inst = cur_inst; | |
| 9292 | continue; | |
| 9293 | } | |
| 9294 | } | |
| 9295 | ||
| 9278 | 9296 | if (types_match_const_cast_only(ira, prev_type, cur_type, source_node, false).id == ConstCastResultIdOk) { |
| 9279 | 9297 | continue; |
| 9280 | 9298 | } |
test/stage1/behavior/pointers.zig+15| ... | ... | @@ -82,3 +82,18 @@ test "C pointer comparison and arithmetic" { |
| 82 | 82 | S.doTheTest(); |
| 83 | 83 | comptime S.doTheTest(); |
| 84 | 84 | } |
| 85 | ||
| 86 | test "peer type resolution with C pointers" { | |
| 87 | var ptr_one: *u8 = undefined; | |
| 88 | var ptr_many: [*]u8 = undefined; | |
| 89 | var ptr_c: [*c]u8 = undefined; | |
| 90 | var t = true; | |
| 91 | var x1 = if (t) ptr_one else ptr_c; | |
| 92 | var x2 = if (t) ptr_many else ptr_c; | |
| 93 | var x3 = if (t) ptr_c else ptr_one; | |
| 94 | var x4 = if (t) ptr_c else ptr_many; | |
| 95 | expect(@typeOf(x1) == [*c]u8); | |
| 96 | expect(@typeOf(x2) == [*c]u8); | |
| 97 | expect(@typeOf(x3) == [*c]u8); | |
| 98 | expect(@typeOf(x4) == [*c]u8); | |
| 99 | } |