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

This commit is contained in:
Cody Tapscott 2022-07-07 11:21:39 -07:00 committed by Veikka Tuominen
parent 75c33ba85e
commit cbc85f4516
3 changed files with 14 additions and 0 deletions

View File

@ -21575,6 +21575,7 @@ done_with_return_type:
// handle `[N]T`
target_len = target->type->data.array.len;
target_sentinel = target->type->data.array.sentinel;
expand_undef_array(ira->codegen, target);
target_elements = target->data.x_array.data.s_none.elements;
break;
} else if (target->type->id == ZigTypeIdPointer && target->type->data.pointer.child_type->id == ZigTypeIdArray) {

View File

@ -83,6 +83,7 @@ test {
_ = @import("behavior/bugs/11181.zig");
_ = @import("behavior/bugs/11213.zig");
_ = @import("behavior/bugs/12003.zig");
_ = @import("behavior/bugs/12033.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@ -0,0 +1,12 @@
const std = @import("std");
test {
const string = "Hello!\x00World!";
try std.testing.expect(@TypeOf(string) == *const [13:0]u8);
const slice_without_sentinel: []const u8 = string[0..6];
try std.testing.expect(@TypeOf(slice_without_sentinel) == []const u8);
const slice_with_sentinel: [:0]const u8 = string[0..6 :0];
try std.testing.expect(@TypeOf(slice_with_sentinel) == [:0]const u8);
}