| ... | @@ -1348,7 +1348,7 @@ static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_ | ... | @@ -1348,7 +1348,7 @@ static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_ |
| 1348 | | 1348 | |
| 1349 | static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1349 | static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1350 | IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, | 1350 | IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, |
| 1351 | IrInstruction *align_value, uint32_t bit_offset_start, uint32_t host_int_bytes) | 1351 | IrInstruction *align_value, uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero) |
| 1352 | { | 1352 | { |
| 1353 | IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node); | 1353 | IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node); |
| 1354 | ptr_type_of_instruction->align_value = align_value; | 1354 | ptr_type_of_instruction->align_value = align_value; |
| ... | @@ -1358,6 +1358,7 @@ static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *s | ... | @@ -1358,6 +1358,7 @@ static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 1358 | ptr_type_of_instruction->ptr_len = ptr_len; | 1358 | ptr_type_of_instruction->ptr_len = ptr_len; |
| 1359 | ptr_type_of_instruction->bit_offset_start = bit_offset_start; | 1359 | ptr_type_of_instruction->bit_offset_start = bit_offset_start; |
| 1360 | ptr_type_of_instruction->host_int_bytes = host_int_bytes; | 1360 | ptr_type_of_instruction->host_int_bytes = host_int_bytes; |
| | 1361 | ptr_type_of_instruction->is_allow_zero = is_allow_zero; |
| 1361 | | 1362 | |
| 1362 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); | 1363 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); |
| 1363 | ir_ref_instruction(child_type, irb->current_basic_block); | 1364 | ir_ref_instruction(child_type, irb->current_basic_block); |
| ... | @@ -1627,13 +1628,14 @@ static IrInstruction *ir_build_promise_type(IrBuilder *irb, Scope *scope, AstNod | ... | @@ -1627,13 +1628,14 @@ static IrInstruction *ir_build_promise_type(IrBuilder *irb, Scope *scope, AstNod |
| 1627 | } | 1628 | } |
| 1628 | | 1629 | |
| 1629 | static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node, | 1630 | static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1630 | IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value) | 1631 | IrInstruction *child_type, bool is_const, bool is_volatile, IrInstruction *align_value, bool is_allow_zero) |
| 1631 | { | 1632 | { |
| 1632 | IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node); | 1633 | IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node); |
| 1633 | instruction->is_const = is_const; | 1634 | instruction->is_const = is_const; |
| 1634 | instruction->is_volatile = is_volatile; | 1635 | instruction->is_volatile = is_volatile; |
| 1635 | instruction->child_type = child_type; | 1636 | instruction->child_type = child_type; |
| 1636 | instruction->align_value = align_value; | 1637 | instruction->align_value = align_value; |
| | 1638 | instruction->is_allow_zero = is_allow_zero; |
| 1637 | | 1639 | |
| 1638 | ir_ref_instruction(child_type, irb->current_basic_block); | 1640 | ir_ref_instruction(child_type, irb->current_basic_block); |
| 1639 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); | 1641 | if (align_value) ir_ref_instruction(align_value, irb->current_basic_block); |
| ... | @@ -5192,6 +5194,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5192,6 +5194,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 5192 | PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id); | 5194 | PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id); |
| 5193 | bool is_const = node->data.pointer_type.is_const; | 5195 | bool is_const = node->data.pointer_type.is_const; |
| 5194 | bool is_volatile = node->data.pointer_type.is_volatile; | 5196 | bool is_volatile = node->data.pointer_type.is_volatile; |
| | 5197 | bool is_allow_zero = node->data.pointer_type.allow_zero_token != nullptr; |
| 5195 | AstNode *expr_node = node->data.pointer_type.op_expr; | 5198 | AstNode *expr_node = node->data.pointer_type.op_expr; |
| 5196 | AstNode *align_expr = node->data.pointer_type.align_expr; | 5199 | AstNode *align_expr = node->data.pointer_type.align_expr; |
| 5197 | | 5200 | |
| ... | @@ -5239,7 +5242,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -5239,7 +5242,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode |
| 5239 | } | 5242 | } |
| 5240 | | 5243 | |
| 5241 | return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile, | 5244 | return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile, |
| 5242 | ptr_len, align_value, bit_offset_start, host_int_bytes); | 5245 | ptr_len, align_value, bit_offset_start, host_int_bytes, is_allow_zero); |
| 5243 | } | 5246 | } |
| 5244 | | 5247 | |
| 5245 | static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node, | 5248 | static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node, AstNode *expr_node, |
| ... | @@ -5826,6 +5829,7 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5826,6 +5829,7 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 5826 | AstNode *child_type_node = node->data.array_type.child_type; | 5829 | AstNode *child_type_node = node->data.array_type.child_type; |
| 5827 | bool is_const = node->data.array_type.is_const; | 5830 | bool is_const = node->data.array_type.is_const; |
| 5828 | bool is_volatile = node->data.array_type.is_volatile; | 5831 | bool is_volatile = node->data.array_type.is_volatile; |
| | 5832 | bool is_allow_zero = node->data.array_type.allow_zero_token != nullptr; |
| 5829 | AstNode *align_expr = node->data.array_type.align_expr; | 5833 | AstNode *align_expr = node->data.array_type.align_expr; |
| 5830 | | 5834 | |
| 5831 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); | 5835 | Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope); |
| ... | @@ -5838,6 +5842,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5838,6 +5842,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 5838 | add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type")); | 5842 | add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type")); |
| 5839 | return irb->codegen->invalid_instruction; | 5843 | return irb->codegen->invalid_instruction; |
| 5840 | } | 5844 | } |
| | 5845 | if (is_allow_zero) { |
| | 5846 | add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type")); |
| | 5847 | return irb->codegen->invalid_instruction; |
| | 5848 | } |
| 5841 | if (align_expr != nullptr) { | 5849 | if (align_expr != nullptr) { |
| 5842 | add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type")); | 5850 | add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type")); |
| 5843 | return irb->codegen->invalid_instruction; | 5851 | return irb->codegen->invalid_instruction; |
| ... | @@ -5866,7 +5874,7 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n | ... | @@ -5866,7 +5874,7 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n |
| 5866 | if (child_type == irb->codegen->invalid_instruction) | 5874 | if (child_type == irb->codegen->invalid_instruction) |
| 5867 | return child_type; | 5875 | return child_type; |
| 5868 | | 5876 | |
| 5869 | return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, align_value); | 5877 | return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, align_value, is_allow_zero); |
| 5870 | } | 5878 | } |
| 5871 | } | 5879 | } |
| 5872 | | 5880 | |
| ... | @@ -7760,7 +7768,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -7760,7 +7768,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7760 | if (type_has_bits(return_type)) { | 7768 | if (type_has_bits(return_type)) { |
| 7761 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, | 7769 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, |
| 7762 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, | 7770 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, |
| 7763 | false, false, PtrLenUnknown, 0, 0, 0)); | 7771 | false, false, PtrLenUnknown, 0, 0, 0, false)); |
| 7764 | IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr); | 7772 | IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr); |
| 7765 | IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast_src(irb, scope, node, u8_ptr_type_unknown_len, | 7773 | IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast_src(irb, scope, node, u8_ptr_type_unknown_len, |
| 7766 | result_ptr, false); | 7774 | result_ptr, false); |
| ... | @@ -7814,7 +7822,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -7814,7 +7822,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7814 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); | 7822 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); |
| 7815 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, | 7823 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, |
| 7816 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, | 7824 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, |
| 7817 | false, false, PtrLenUnknown, 0, 0, 0)); | 7825 | false, false, PtrLenUnknown, 0, 0, 0, false)); |
| 7818 | IrInstruction *coro_mem_ptr = ir_build_ptr_cast_src(irb, scope, node, u8_ptr_type_unknown_len, | 7826 | IrInstruction *coro_mem_ptr = ir_build_ptr_cast_src(irb, scope, node, u8_ptr_type_unknown_len, |
| 7819 | coro_mem_ptr_maybe, false); | 7827 | coro_mem_ptr_maybe, false); |
| 7820 | IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false); | 7828 | IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false); |
| ... | @@ -9818,7 +9826,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -9818,7 +9826,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9818 | ZigType *ptr_type = get_pointer_to_type_extra( | 9826 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 9819 | ira->codegen, prev_inst->value.type->data.array.child_type, | 9827 | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 9820 | true, false, PtrLenUnknown, | 9828 | true, false, PtrLenUnknown, |
| 9821 | 0, 0, 0); | 9829 | 0, 0, 0, false); |
| 9822 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); | 9830 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); |
| 9823 | if (err_set_type != nullptr) { | 9831 | if (err_set_type != nullptr) { |
| 9824 | return get_error_union_type(ira->codegen, err_set_type, slice_type); | 9832 | return get_error_union_type(ira->codegen, err_set_type, slice_type); |
| ... | @@ -10243,7 +10251,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio | ... | @@ -10243,7 +10251,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 10243 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) | 10251 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 10244 | { | 10252 | { |
| 10245 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, | 10253 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 10246 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0); | 10254 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); |
| 10247 | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); | 10255 | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); |
| 10248 | ConstExprValue *const_val = &const_instr->value; | 10256 | ConstExprValue *const_val = &const_instr->value; |
| 10249 | const_val->data.x_ptr.special = ConstPtrSpecialRef; | 10257 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| ... | @@ -10576,7 +10584,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi | ... | @@ -10576,7 +10584,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 10576 | } | 10584 | } |
| 10577 | | 10585 | |
| 10578 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, | 10586 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, |
| 10579 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); | 10587 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 10580 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, | 10588 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, |
| 10581 | source_instruction->source_node, value, is_const, is_volatile); | 10589 | source_instruction->source_node, value, is_const, is_volatile); |
| 10582 | new_instruction->value.type = ptr_type; | 10590 | new_instruction->value.type = ptr_type; |
| ... | @@ -11983,7 +11991,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { | ... | @@ -11983,7 +11991,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11983 | return nullptr; | 11991 | return nullptr; |
| 11984 | | 11992 | |
| 11985 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 11993 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 11986 | true, false, PtrLenUnknown, 0, 0, 0); | 11994 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 11987 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); | 11995 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 11988 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); | 11996 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 11989 | if (type_is_invalid(casted_value->value.type)) | 11997 | if (type_is_invalid(casted_value->value.type)) |
| ... | @@ -13154,7 +13162,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i | ... | @@ -13154,7 +13162,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 13154 | out_array_val = out_val; | 13162 | out_array_val = out_val; |
| 13155 | } else if (is_slice(op1_type) || is_slice(op2_type)) { | 13163 | } else if (is_slice(op1_type) || is_slice(op2_type)) { |
| 13156 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, | 13164 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 13157 | true, false, PtrLenUnknown, 0, 0, 0); | 13165 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 13158 | result->value.type = get_slice_type(ira->codegen, ptr_type); | 13166 | result->value.type = get_slice_type(ira->codegen, ptr_type); |
| 13159 | out_array_val = create_const_vals(1); | 13167 | out_array_val = create_const_vals(1); |
| 13160 | out_array_val->special = ConstValSpecialStatic; | 13168 | out_array_val->special = ConstValSpecialStatic; |
| ... | @@ -13175,7 +13183,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i | ... | @@ -13175,7 +13183,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 13175 | new_len += 1; // null byte | 13183 | new_len += 1; // null byte |
| 13176 | | 13184 | |
| 13177 | // TODO make this `[*]null T` instead of `[*]T` | 13185 | // TODO make this `[*]null T` instead of `[*]T` |
| 13178 | result->value.type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0); | 13186 | result->value.type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0, false); |
| 13179 | | 13187 | |
| 13180 | out_array_val = create_const_vals(1); | 13188 | out_array_val = create_const_vals(1); |
| 13181 | out_array_val->special = ConstValSpecialStatic; | 13189 | out_array_val->special = ConstValSpecialStatic; |
| ... | @@ -14033,7 +14041,7 @@ no_mem_slot: | ... | @@ -14033,7 +14041,7 @@ no_mem_slot: |
| 14033 | IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb, | 14041 | IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb, |
| 14034 | instruction->scope, instruction->source_node, var); | 14042 | instruction->scope, instruction->source_node, var); |
| 14035 | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, | 14043 | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 14036 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0); | 14044 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 14037 | | 14045 | |
| 14038 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); | 14046 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 14039 | var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; | 14047 | var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| ... | @@ -14328,7 +14336,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call | ... | @@ -14328,7 +14336,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call |
| 14328 | IrInstruction *casted_new_stack = nullptr; | 14336 | IrInstruction *casted_new_stack = nullptr; |
| 14329 | if (call_instruction->new_stack != nullptr) { | 14337 | if (call_instruction->new_stack != nullptr) { |
| 14330 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 14338 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 14331 | false, false, PtrLenUnknown, 0, 0, 0); | 14339 | false, false, PtrLenUnknown, 0, 0, 0, false); |
| 14332 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 14340 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 14333 | IrInstruction *new_stack = call_instruction->new_stack->child; | 14341 | IrInstruction *new_stack = call_instruction->new_stack->child; |
| 14334 | if (type_is_invalid(new_stack->value.type)) | 14342 | if (type_is_invalid(new_stack->value.type)) |
| ... | @@ -15262,7 +15270,8 @@ static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_ali | ... | @@ -15262,7 +15270,8 @@ static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_ali |
| 15262 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 15270 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15263 | ptr_type->data.pointer.ptr_len, | 15271 | ptr_type->data.pointer.ptr_len, |
| 15264 | new_align, | 15272 | new_align, |
| 15265 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes); | 15273 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes, |
| | 15274 | ptr_type->data.pointer.allow_zero); |
| 15266 | } | 15275 | } |
| 15267 | | 15276 | |
| 15268 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) { | 15277 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) { |
| ... | @@ -15279,7 +15288,8 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { | ... | @@ -15279,7 +15288,8 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 15279 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 15288 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15280 | ptr_len, | 15289 | ptr_len, |
| 15281 | ptr_type->data.pointer.explicit_alignment, | 15290 | ptr_type->data.pointer.explicit_alignment, |
| 15282 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes); | 15291 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes, |
| | 15292 | ptr_type->data.pointer.allow_zero); |
| 15283 | } | 15293 | } |
| 15284 | | 15294 | |
| 15285 | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { | 15295 | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| ... | @@ -15330,7 +15340,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -15330,7 +15340,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 15330 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, | 15340 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15331 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 15341 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15332 | elem_ptr_instruction->ptr_len, | 15342 | elem_ptr_instruction->ptr_len, |
| 15333 | ptr_type->data.pointer.explicit_alignment, 0, 0); | 15343 | ptr_type->data.pointer.explicit_alignment, 0, 0, false); |
| 15334 | } else { | 15344 | } else { |
| 15335 | uint64_t elem_val_scalar; | 15345 | uint64_t elem_val_scalar; |
| 15336 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) | 15346 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) |
| ... | @@ -15342,7 +15352,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct | ... | @@ -15342,7 +15352,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 15342 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, | 15352 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15343 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 15353 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15344 | elem_ptr_instruction->ptr_len, | 15354 | elem_ptr_instruction->ptr_len, |
| 15345 | 1, (uint32_t)bit_offset, ptr_type->data.pointer.host_int_bytes); | 15355 | 1, (uint32_t)bit_offset, ptr_type->data.pointer.host_int_bytes, false); |
| 15346 | } | 15356 | } |
| 15347 | } else if (array_type->id == ZigTypeIdPointer) { | 15357 | } else if (array_type->id == ZigTypeIdPointer) { |
| 15348 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { | 15358 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| ... | @@ -15693,7 +15703,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -15693,7 +15703,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 15693 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, | 15703 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, |
| 15694 | is_const, is_volatile, PtrLenSingle, align_bytes, | 15704 | is_const, is_volatile, PtrLenSingle, align_bytes, |
| 15695 | (uint32_t)(ptr_bit_offset + field->bit_offset_in_host), | 15705 | (uint32_t)(ptr_bit_offset + field->bit_offset_in_host), |
| 15696 | (uint32_t)host_int_bytes_for_result_type); | 15706 | (uint32_t)host_int_bytes_for_result_type, false); |
| 15697 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); | 15707 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 15698 | ConstExprValue *const_val = &result->value; | 15708 | ConstExprValue *const_val = &result->value; |
| 15699 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; | 15709 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| ... | @@ -15709,7 +15719,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -15709,7 +15719,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 15709 | PtrLenSingle, | 15719 | PtrLenSingle, |
| 15710 | align_bytes, | 15720 | align_bytes, |
| 15711 | (uint32_t)(ptr_bit_offset + field->bit_offset_in_host), | 15721 | (uint32_t)(ptr_bit_offset + field->bit_offset_in_host), |
| 15712 | host_int_bytes_for_result_type); | 15722 | host_int_bytes_for_result_type, false); |
| 15713 | return result; | 15723 | return result; |
| 15714 | } else { | 15724 | } else { |
| 15715 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 15725 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| ... | @@ -15748,7 +15758,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -15748,7 +15758,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 15748 | | 15758 | |
| 15749 | ZigType *field_type = field->type_entry; | 15759 | ZigType *field_type = field->type_entry; |
| 15750 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, | 15760 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 15751 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); | 15761 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 15752 | | 15762 | |
| 15753 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); | 15763 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 15754 | ConstExprValue *const_val = &result->value; | 15764 | ConstExprValue *const_val = &result->value; |
| ... | @@ -15761,7 +15771,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -15761,7 +15771,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 15761 | | 15771 | |
| 15762 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field); | 15772 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field); |
| 15763 | result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, | 15773 | result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, |
| 15764 | PtrLenSingle, 0, 0, 0); | 15774 | PtrLenSingle, 0, 0, 0, false); |
| 15765 | return result; | 15775 | return result; |
| 15766 | } else { | 15776 | } else { |
| 15767 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 15777 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| ... | @@ -16480,6 +16490,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -16480,6 +16490,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 16480 | | 16490 | |
| 16481 | bool is_const = slice_type_instruction->is_const; | 16491 | bool is_const = slice_type_instruction->is_const; |
| 16482 | bool is_volatile = slice_type_instruction->is_volatile; | 16492 | bool is_volatile = slice_type_instruction->is_volatile; |
| | 16493 | bool is_allow_zero = slice_type_instruction->is_allow_zero; |
| 16483 | | 16494 | |
| 16484 | switch (child_type->id) { | 16495 | switch (child_type->id) { |
| 16485 | case ZigTypeIdInvalid: // handled above | 16496 | case ZigTypeIdInvalid: // handled above |
| ... | @@ -16516,7 +16527,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -16516,7 +16527,7 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 16516 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) | 16527 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) |
| 16517 | return ira->codegen->invalid_instruction; | 16528 | return ira->codegen->invalid_instruction; |
| 16518 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, | 16529 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 16519 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); | 16530 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0, is_allow_zero); |
| 16520 | ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type); | 16531 | ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 16521 | return ir_const_type(ira, &slice_type_instruction->base, result_type); | 16532 | return ir_const_type(ira, &slice_type_instruction->base, result_type); |
| 16522 | } | 16533 | } |
| ... | @@ -16749,7 +16760,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr | ... | @@ -16749,7 +16760,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 16749 | | 16760 | |
| 16750 | ZigType *child_type = type_entry->data.maybe.child_type; | 16761 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 16751 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, | 16762 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 16752 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0); | 16763 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 16753 | | 16764 | |
| 16754 | if (instr_is_comptime(base_ptr)) { | 16765 | if (instr_is_comptime(base_ptr)) { |
| 16755 | ConstExprValue *val = ir_resolve_const(ira, base_ptr, UndefBad); | 16766 | ConstExprValue *val = ir_resolve_const(ira, base_ptr, UndefBad); |
| ... | @@ -17668,7 +17679,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct | ... | @@ -17668,7 +17679,7 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 17668 | return ira->codegen->invalid_instruction; | 17679 | return ira->codegen->invalid_instruction; |
| 17669 | | 17680 | |
| 17670 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 17681 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 17671 | true, false, PtrLenUnknown, 0, 0, 0); | 17682 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 17672 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); | 17683 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 17673 | if (casted_value->value.special == ConstValSpecialStatic) { | 17684 | if (casted_value->value.special == ConstValSpecialStatic) { |
| 17674 | ErrorTableEntry *err = casted_value->value.data.x_err_set; | 17685 | ErrorTableEntry *err = casted_value->value.data.x_err_set; |
| ... | @@ -17713,7 +17724,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns | ... | @@ -17713,7 +17724,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 17713 | ZigType *u8_ptr_type = get_pointer_to_type_extra( | 17724 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 17714 | ira->codegen, ira->codegen->builtin_types.entry_u8, | 17725 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 17715 | true, false, PtrLenUnknown, | 17726 | true, false, PtrLenUnknown, |
| 17716 | 0, 0, 0); | 17727 | 0, 0, 0, false); |
| 17717 | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); | 17728 | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); |
| 17718 | return result; | 17729 | return result; |
| 17719 | } | 17730 | } |
| ... | @@ -17767,7 +17778,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -17767,7 +17778,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17767 | field_ptr->value.type->data.pointer.is_const, | 17778 | field_ptr->value.type->data.pointer.is_const, |
| 17768 | field_ptr->value.type->data.pointer.is_volatile, | 17779 | field_ptr->value.type->data.pointer.is_volatile, |
| 17769 | PtrLenSingle, | 17780 | PtrLenSingle, |
| 17770 | field_ptr_align, 0, 0); | 17781 | field_ptr_align, 0, 0, false); |
| 17771 | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); | 17782 | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 17772 | if (type_is_invalid(casted_field_ptr->value.type)) | 17783 | if (type_is_invalid(casted_field_ptr->value.type)) |
| 17773 | return ira->codegen->invalid_instruction; | 17784 | return ira->codegen->invalid_instruction; |
| ... | @@ -17776,7 +17787,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, | ... | @@ -17776,7 +17787,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 17776 | casted_field_ptr->value.type->data.pointer.is_const, | 17787 | casted_field_ptr->value.type->data.pointer.is_const, |
| 17777 | casted_field_ptr->value.type->data.pointer.is_volatile, | 17788 | casted_field_ptr->value.type->data.pointer.is_volatile, |
| 17778 | PtrLenSingle, | 17789 | PtrLenSingle, |
| 17779 | parent_ptr_align, 0, 0); | 17790 | parent_ptr_align, 0, 0, false); |
| 17780 | | 17791 | |
| 17781 | if (instr_is_comptime(casted_field_ptr)) { | 17792 | if (instr_is_comptime(casted_field_ptr)) { |
| 17782 | ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); | 17793 | ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); |
| ... | @@ -18112,7 +18123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, IrInstruction *source_instr, | ... | @@ -18112,7 +18123,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, IrInstruction *source_instr, |
| 18112 | ZigType *u8_ptr = get_pointer_to_type_extra( | 18123 | ZigType *u8_ptr = get_pointer_to_type_extra( |
| 18113 | ira->codegen, ira->codegen->builtin_types.entry_u8, | 18124 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 18114 | true, false, PtrLenUnknown, | 18125 | true, false, PtrLenUnknown, |
| 18115 | 0, 0, 0); | 18126 | 0, 0, 0, false); |
| 18116 | fn_def_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); | 18127 | fn_def_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); |
| 18117 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { | 18128 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { |
| 18118 | fn_def_fields[6].data.x_optional = create_const_vals(1); | 18129 | fn_def_fields[6].data.x_optional = create_const_vals(1); |
| ... | @@ -18216,7 +18227,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty | ... | @@ -18216,7 +18227,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 18216 | result->special = ConstValSpecialStatic; | 18227 | result->special = ConstValSpecialStatic; |
| 18217 | result->type = type_info_pointer_type; | 18228 | result->type = type_info_pointer_type; |
| 18218 | | 18229 | |
| 18219 | ConstExprValue *fields = create_const_vals(5); | 18230 | ConstExprValue *fields = create_const_vals(6); |
| 18220 | result->data.x_struct.fields = fields; | 18231 | result->data.x_struct.fields = fields; |
| 18221 | | 18232 | |
| 18222 | // size: Size | 18233 | // size: Size |
| ... | @@ -18247,6 +18258,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty | ... | @@ -18247,6 +18258,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 18247 | fields[4].special = ConstValSpecialStatic; | 18258 | fields[4].special = ConstValSpecialStatic; |
| 18248 | fields[4].type = ira->codegen->builtin_types.entry_type; | 18259 | fields[4].type = ira->codegen->builtin_types.entry_type; |
| 18249 | fields[4].data.x_type = attrs_type->data.pointer.child_type; | 18260 | fields[4].data.x_type = attrs_type->data.pointer.child_type; |
| | 18261 | // is_allowzero: bool |
| | 18262 | ensure_field_index(result->type, "is_allowzero", 5); |
| | 18263 | fields[5].special = ConstValSpecialStatic; |
| | 18264 | fields[5].type = ira->codegen->builtin_types.entry_bool; |
| | 18265 | fields[5].data.x_bool = attrs_type->data.pointer.allow_zero; |
| 18250 | | 18266 | |
| 18251 | return result; | 18267 | return result; |
| 18252 | }; | 18268 | }; |
| ... | @@ -19473,12 +19489,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru | ... | @@ -19473,12 +19489,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 19473 | | 19489 | |
| 19474 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, | 19490 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, |
| 19475 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, | 19491 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| 19476 | src_ptr_align, 0, 0); | 19492 | src_ptr_align, 0, 0, false); |
| 19477 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); | 19493 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 19478 | | 19494 | |
| 19479 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 19495 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 19480 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, | 19496 | src_ptr_const, src_ptr_volatile, PtrLenUnknown, |
| 19481 | src_ptr_align, 0, 0); | 19497 | src_ptr_align, 0, 0, false); |
| 19482 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 19498 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 19483 | | 19499 | |
| 19484 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); | 19500 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| ... | @@ -19545,7 +19561,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct | ... | @@ -19545,7 +19561,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 19545 | | 19561 | |
| 19546 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 19562 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 19547 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, | 19563 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| 19548 | alignment, 0, 0); | 19564 | alignment, 0, 0, false); |
| 19549 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); | 19565 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 19550 | | 19566 | |
| 19551 | if (instr_is_comptime(target)) { | 19567 | if (instr_is_comptime(target)) { |
| ... | @@ -19773,7 +19789,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio | ... | @@ -19773,7 +19789,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 19773 | dest_align = get_abi_alignment(ira->codegen, u8); | 19789 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 19774 | } | 19790 | } |
| 19775 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, | 19791 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 19776 | PtrLenUnknown, dest_align, 0, 0); | 19792 | PtrLenUnknown, dest_align, 0, 0, false); |
| 19777 | | 19793 | |
| 19778 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); | 19794 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 19779 | if (type_is_invalid(casted_dest_ptr->value.type)) | 19795 | if (type_is_invalid(casted_dest_ptr->value.type)) |
| ... | @@ -19895,9 +19911,9 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio | ... | @@ -19895,9 +19911,9 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 19895 | | 19911 | |
| 19896 | ZigType *usize = ira->codegen->builtin_types.entry_usize; | 19912 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 19897 | ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, | 19913 | ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 19898 | PtrLenUnknown, dest_align, 0, 0); | 19914 | PtrLenUnknown, dest_align, 0, 0, false); |
| 19899 | ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, | 19915 | ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, |
| 19900 | PtrLenUnknown, src_align, 0, 0); | 19916 | PtrLenUnknown, src_align, 0, 0, false); |
| 19901 | | 19917 | |
| 19902 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); | 19918 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 19903 | if (type_is_invalid(casted_dest_ptr->value.type)) | 19919 | if (type_is_invalid(casted_dest_ptr->value.type)) |
| ... | @@ -20061,7 +20077,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -20061,7 +20077,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 20061 | ptr_ptr_type->data.pointer.is_const || is_comptime_const, | 20077 | ptr_ptr_type->data.pointer.is_const || is_comptime_const, |
| 20062 | ptr_ptr_type->data.pointer.is_volatile, | 20078 | ptr_ptr_type->data.pointer.is_volatile, |
| 20063 | PtrLenUnknown, | 20079 | PtrLenUnknown, |
| 20064 | ptr_ptr_type->data.pointer.explicit_alignment, 0, 0); | 20080 | ptr_ptr_type->data.pointer.explicit_alignment, 0, 0, false); |
| 20065 | return_type = get_slice_type(ira->codegen, slice_ptr_type); | 20081 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 20066 | } else if (array_type->id == ZigTypeIdPointer) { | 20082 | } else if (array_type->id == ZigTypeIdPointer) { |
| 20067 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { | 20083 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| ... | @@ -20071,7 +20087,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction | ... | @@ -20071,7 +20087,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 20071 | main_type->data.pointer.child_type, | 20087 | main_type->data.pointer.child_type, |
| 20072 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, | 20088 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 20073 | PtrLenUnknown, | 20089 | PtrLenUnknown, |
| 20074 | array_type->data.pointer.explicit_alignment, 0, 0); | 20090 | array_type->data.pointer.explicit_alignment, 0, 0, false); |
| 20075 | return_type = get_slice_type(ira->codegen, slice_ptr_type); | 20091 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 20076 | } else { | 20092 | } else { |
| 20077 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); | 20093 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); |
| ... | @@ -20586,7 +20602,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr | ... | @@ -20586,7 +20602,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 20586 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, | 20602 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 20587 | false, result_ptr->value.type->data.pointer.is_volatile, | 20603 | false, result_ptr->value.type->data.pointer.is_volatile, |
| 20588 | PtrLenSingle, | 20604 | PtrLenSingle, |
| 20589 | alignment, 0, 0); | 20605 | alignment, 0, 0, false); |
| 20590 | } else { | 20606 | } else { |
| 20591 | expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); | 20607 | expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); |
| 20592 | } | 20608 | } |
| ... | @@ -20753,7 +20769,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, | ... | @@ -20753,7 +20769,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 20753 | | 20769 | |
| 20754 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, | 20770 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 20755 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 20771 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 20756 | PtrLenSingle, 0, 0, 0); | 20772 | PtrLenSingle, 0, 0, 0, false); |
| 20757 | if (instr_is_comptime(value)) { | 20773 | if (instr_is_comptime(value)) { |
| 20758 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); | 20774 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 20759 | if (!ptr_val) | 20775 | if (!ptr_val) |
| ... | @@ -21125,7 +21141,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction | ... | @@ -21125,7 +21141,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction |
| 21125 | } | 21141 | } |
| 21126 | | 21142 | |
| 21127 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 21143 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 21128 | true, false, PtrLenUnknown, 0, 0, 0); | 21144 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 21129 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); | 21145 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 21130 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); | 21146 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 21131 | if (type_is_invalid(casted_msg->value.type)) | 21147 | if (type_is_invalid(casted_msg->value.type)) |
| ... | @@ -21794,10 +21810,17 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc | ... | @@ -21794,10 +21810,17 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 21794 | if (!val) | 21810 | if (!val) |
| 21795 | return ira->codegen->invalid_instruction; | 21811 | return ira->codegen->invalid_instruction; |
| 21796 | | 21812 | |
| | 21813 | uint64_t addr = bigint_as_unsigned(&val->data.x_bigint); |
| | 21814 | if (!ptr_allows_addr_zero(ptr_type) && addr == 0) { |
| | 21815 | ir_add_error(ira, source_instr, |
| | 21816 | buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name))); |
| | 21817 | return ira->codegen->invalid_instruction; |
| | 21818 | } |
| | 21819 | |
| 21797 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); | 21820 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 21798 | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; | 21821 | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 21799 | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; | 21822 | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 21800 | result->value.data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&val->data.x_bigint); | 21823 | result->value.data.x_ptr.data.hard_coded_addr.addr = addr; |
| 21801 | return result; | 21824 | return result; |
| 21802 | } | 21825 | } |
| 21803 | | 21826 | |
| ... | @@ -21951,6 +21974,9 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct | ... | @@ -21951,6 +21974,9 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 21951 | } else if (child_type->id == ZigTypeIdOpaque) { | 21974 | } else if (child_type->id == ZigTypeIdOpaque) { |
| 21952 | ir_add_error(ira, &instruction->base, buf_sprintf("C pointers cannot point opaque types")); | 21975 | ir_add_error(ira, &instruction->base, buf_sprintf("C pointers cannot point opaque types")); |
| 21953 | return ira->codegen->invalid_instruction; | 21976 | return ira->codegen->invalid_instruction; |
| | 21977 | } else if (instruction->is_allow_zero) { |
| | 21978 | ir_add_error(ira, &instruction->base, buf_sprintf("C pointers always allow address zero")); |
| | 21979 | return ira->codegen->invalid_instruction; |
| 21954 | } | 21980 | } |
| 21955 | } | 21981 | } |
| 21956 | | 21982 | |
| ... | @@ -21969,10 +21995,12 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct | ... | @@ -21969,10 +21995,12 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 21969 | align_bytes = 0; | 21995 | align_bytes = 0; |
| 21970 | } | 21996 | } |
| 21971 | | 21997 | |
| | 21998 | bool allow_zero = instruction->is_allow_zero || instruction->ptr_len == PtrLenC; |
| | 21999 | |
| 21972 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, | 22000 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 21973 | instruction->is_const, instruction->is_volatile, | 22001 | instruction->is_const, instruction->is_volatile, |
| 21974 | instruction->ptr_len, align_bytes, | 22002 | instruction->ptr_len, align_bytes, |
| 21975 | instruction->bit_offset_start, instruction->host_int_bytes); | 22003 | instruction->bit_offset_start, instruction->host_int_bytes, allow_zero); |
| 21976 | return ir_const_type(ira, &instruction->base, result_type); | 22004 | return ir_const_type(ira, &instruction->base, result_type); |
| 21977 | } | 22005 | } |
| 21978 | | 22006 | |