From 15f843e70f18fe0cd7ee31a67af6eb8d6302dcbc Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 26 Dec 2016 17:11:36 -0500 Subject: IR: pass castSliceToU8Slice test --- src/ir.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index d58c813f3e..8f31bf3b45 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -5220,10 +5220,18 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s source_instr->source_node, ira->codegen->builtin_types.entry_usize, false); init_const_usize(ira->codegen, &end->value, array_type->data.array.len); + bool is_const; + if (array->id == IrInstructionIdLoadPtr) { + IrInstructionLoadPtr *load_ptr_inst = (IrInstructionLoadPtr *) array; + is_const = load_ptr_inst->ptr->value.type->data.pointer.is_const; + } else { + is_const = true; + } + IrInstruction *result = ir_build_slice(&ira->new_irb, source_instr->scope, - source_instr->source_node, array, start, end, true, false); + source_instr->source_node, array, start, end, is_const, false); TypeTableEntry *child_type = array_type->data.array.child_type; - result->value.type = get_slice_type(ira->codegen, child_type, true); + result->value.type = get_slice_type(ira->codegen, child_type, is_const); ir_add_alloca(ira, result, result->value.type); return result; } -- cgit v1.2.3