authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-07-07 11:21:39-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-08 02:14:38+03:00
logcbc85f4516a5bd545ce365dedec19f6fcad47b58
tree85034338c6861eec5217b328fe358e3a4e4d3777
parent75c33ba85e47eec9f7257cfb972a54b22a5283eb

stage1: Fix seg-fault when slicing string literal with sentinel


3 files changed, 14 insertions(+), 0 deletions(-)

src/stage1/ir.cpp+1
......@@ -21575,6 +21575,7 @@ done_with_return_type:
2157521575 // handle `[N]T`
2157621576 target_len = target->type->data.array.len;
2157721577 target_sentinel = target->type->data.array.sentinel;
21578 expand_undef_array(ira->codegen, target);
2157821579 target_elements = target->data.x_array.data.s_none.elements;
2157921580 break;
2158021581 } else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) {
test/behavior.zig+1
......@@ -83,6 +83,7 @@ test {
8383 _ = @import("behavior/bugs/11181.zig");
8484 _ = @import("behavior/bugs/11213.zig");
8585 _ = @import("behavior/bugs/12003.zig");
86 _ = @import("behavior/bugs/12033.zig");
8687 _ = @import("behavior/byteswap.zig");
8788 _ = @import("behavior/byval_arg_var.zig");
8889 _ = @import("behavior/call.zig");
test/behavior/bugs/12033.zig created+12
......@@ -0,0 +1,12 @@
1const std = @import("std");
2
3test {
4 const string = "Hello!\x00World!";
5 try std.testing.expect(@TypeOf(string) == *const [13:0]u8);
6
7 const slice_without_sentinel: []const u8 = string[0..6];
8 try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8);
9
10 const slice_with_sentinel: [:0]const u8 = string[0..6 :0];
11 try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8);
12}