diff --git a/lib/std/crypto/sha2.zig b/lib/std/crypto/sha2.zig index fd7ad532a3..f004bceac3 100644 --- a/lib/std/crypto/sha2.zig +++ b/lib/std/crypto/sha2.zig @@ -167,8 +167,7 @@ fn Sha2_32(comptime params: Sha2Params32) type { const rr = d.s[0 .. params.out_len / 32]; for (rr) |s, j| { - // TODO https://github.com/ziglang/zig/issues/863 - mem.writeIntSliceBig(u32, out[4 * j .. 4 * j + 4], s); + mem.writeIntBig(u32, out[4 * j ..][0..4], s); } } @@ -509,8 +508,7 @@ fn Sha2_64(comptime params: Sha2Params64) type { const rr = d.s[0 .. params.out_len / 64]; for (rr) |s, j| { - // TODO https://github.com/ziglang/zig/issues/863 - mem.writeIntSliceBig(u64, out[8 * j .. 8 * j + 8], s); + mem.writeIntBig(u64, out[8 * j ..][0..8], s); } } diff --git a/src/all_types.hpp b/src/all_types.hpp index 5025ff7cb5..6719d78a92 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -3711,6 +3711,7 @@ struct IrInstGenSlice { IrInstGen *start; IrInstGen *end; IrInstGen *result_loc; + ZigValue *sentinel; bool safety_check_on; }; diff --git a/src/codegen.cpp b/src/codegen.cpp index 21e74ba609..8fae16e551 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5425,17 +5425,9 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI return nullptr; } - ZigValue *sentinel = nullptr; - if (result_type->id == ZigTypeIdPointer) { - ZigType *result_array_type = result_type->data.pointer.child_type; - ir_assert(result_array_type->id == ZigTypeIdArray, &instruction->base); - sentinel = result_array_type->data.array.sentinel; - } else if (result_type->id == ZigTypeIdStruct) { - ZigType *res_slice_ptr_type = result_type->data.structure.fields[slice_ptr_index]->type_entry; - sentinel = res_slice_ptr_type->data.pointer.sentinel; - } else { - zig_unreachable(); - } + // This is not whether the result type has a sentinel, but whether there should be a sentinel check, + // e.g. if they used [a..b :s] syntax. + ZigValue *sentinel = instruction->sentinel; if (array_type->id == ZigTypeIdArray || (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) diff --git a/src/ir.cpp b/src/ir.cpp index e20111e21f..8cd780e46d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3732,7 +3732,8 @@ static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *s } static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type, - IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc) + IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc, + ZigValue *sentinel) { IrInstGenSlice *instruction = ir_build_inst_gen( &ira->new_irb, source_instruction->scope, source_instruction->source_node); @@ -3742,6 +3743,7 @@ static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, instruction->end = end; instruction->safety_check_on = safety_check_on; instruction->result_loc = result_loc; + instruction->sentinel = sentinel; ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); ir_ref_inst_gen(start, ira->new_irb.current_basic_block); @@ -26667,7 +26669,7 @@ done_with_return_type: } return ir_build_slice_gen(ira, &instruction->base.base, return_type, ptr_ptr, - casted_start, end, instruction->safety_check_on, result_loc); + casted_start, end, instruction->safety_check_on, result_loc, sentinel_val); } static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {