| ... | ... | @@ -40,6 +40,7 @@ struct IrAnalyze { |
| 40 | 40 | |
| 41 | 41 | enum ConstCastResultId { |
| 42 | 42 | ConstCastResultIdOk, |
| 43 | ConstCastResultIdInvalid, |
| 43 | 44 | ConstCastResultIdErrSet, |
| 44 | 45 | ConstCastResultIdErrSetGlobal, |
| 45 | 46 | ConstCastResultIdPointerChild, |
| ... | ... | @@ -7490,8 +7491,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7490 | 7491 | if (type_has_bits(return_type)) { |
| 7491 | 7492 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, |
| 7492 | 7493 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, |
| 7493 | | false, false, PtrLenUnknown, get_abi_alignment(irb->codegen, irb->codegen->builtin_types.entry_u8), |
| 7494 | | 0, 0)); |
| 7494 | false, false, PtrLenUnknown, 0, 0, 0)); |
| 7495 | 7495 | IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr); |
| 7496 | 7496 | IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, result_ptr); |
| 7497 | 7497 | IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, |
| ... | ... | @@ -7544,8 +7544,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7544 | 7544 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); |
| 7545 | 7545 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, |
| 7546 | 7546 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, |
| 7547 | | false, false, PtrLenUnknown, get_abi_alignment(irb->codegen, irb->codegen->builtin_types.entry_u8), |
| 7548 | | 0, 0)); |
| 7547 | false, false, PtrLenUnknown, 0, 0, 0)); |
| 7549 | 7548 | IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, coro_mem_ptr_maybe); |
| 7550 | 7549 | IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false); |
| 7551 | 7550 | IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var); |
| ... | ... | @@ -8516,6 +8515,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8516 | 8515 | ConstCastOnly result = {}; |
| 8517 | 8516 | result.id = ConstCastResultIdOk; |
| 8518 | 8517 | |
| 8518 | Error err; |
| 8519 | |
| 8519 | 8520 | if (wanted_type == actual_type) |
| 8520 | 8521 | return result; |
| 8521 | 8522 | |
| ... | ... | @@ -8528,6 +8529,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8528 | 8529 | { |
| 8529 | 8530 | ConstCastOnly child = types_match_const_cast_only(ira, |
| 8530 | 8531 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); |
| 8532 | if (child.id == ConstCastResultIdInvalid) |
| 8533 | return child; |
| 8531 | 8534 | if (child.id != ConstCastResultIdOk) { |
| 8532 | 8535 | result.id = ConstCastResultIdNullWrapPtr; |
| 8533 | 8536 | result.data.null_wrap_ptr_child = allocate_nonzero<ConstCastOnly>(1); |
| ... | ... | @@ -8544,7 +8547,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8544 | 8547 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8545 | 8548 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) |
| 8546 | 8549 | { |
| 8547 | | assert(actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment); |
| 8548 | 8550 | return result; |
| 8549 | 8551 | } |
| 8550 | 8552 | |
| ... | ... | @@ -8552,6 +8554,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8552 | 8554 | if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { |
| 8553 | 8555 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 8554 | 8556 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); |
| 8557 | if (child.id == ConstCastResultIdInvalid) |
| 8558 | return child; |
| 8555 | 8559 | if (child.id != ConstCastResultIdOk) { |
| 8556 | 8560 | result.id = ConstCastResultIdPointerChild; |
| 8557 | 8561 | result.data.pointer_mismatch = allocate_nonzero<ConstCastPointerMismatch>(1); |
| ... | ... | @@ -8560,12 +8564,20 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8560 | 8564 | result.data.pointer_mismatch->actual_child = actual_type->data.pointer.child_type; |
| 8561 | 8565 | return result; |
| 8562 | 8566 | } |
| 8567 | if ((err = type_resolve(g, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8568 | result.id = ConstCastResultIdInvalid; |
| 8569 | return result; |
| 8570 | } |
| 8571 | if ((err = type_resolve(g, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8572 | result.id = ConstCastResultIdInvalid; |
| 8573 | return result; |
| 8574 | } |
| 8563 | 8575 | if ((actual_type->data.pointer.ptr_len == wanted_type->data.pointer.ptr_len) && |
| 8564 | 8576 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8565 | 8577 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile) && |
| 8566 | 8578 | actual_type->data.pointer.bit_offset == wanted_type->data.pointer.bit_offset && |
| 8567 | 8579 | actual_type->data.pointer.unaligned_bit_count == wanted_type->data.pointer.unaligned_bit_count && |
| 8568 | | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment) |
| 8580 | get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type)) |
| 8569 | 8581 | { |
| 8570 | 8582 | return result; |
| 8571 | 8583 | } |
| ... | ... | @@ -8575,14 +8587,24 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8575 | 8587 | if (is_slice(wanted_type) && is_slice(actual_type)) { |
| 8576 | 8588 | ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8577 | 8589 | ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8590 | if ((err = type_resolve(g, actual_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8591 | result.id = ConstCastResultIdInvalid; |
| 8592 | return result; |
| 8593 | } |
| 8594 | if ((err = type_resolve(g, wanted_ptr_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) { |
| 8595 | result.id = ConstCastResultIdInvalid; |
| 8596 | return result; |
| 8597 | } |
| 8578 | 8598 | if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && |
| 8579 | 8599 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && |
| 8580 | 8600 | actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset && |
| 8581 | 8601 | actual_ptr_type->data.pointer.unaligned_bit_count == wanted_ptr_type->data.pointer.unaligned_bit_count && |
| 8582 | | actual_ptr_type->data.pointer.alignment >= wanted_ptr_type->data.pointer.alignment) |
| 8602 | get_ptr_align(g, actual_ptr_type) >= get_ptr_align(g, wanted_ptr_type)) |
| 8583 | 8603 | { |
| 8584 | 8604 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type, |
| 8585 | 8605 | actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const); |
| 8606 | if (child.id == ConstCastResultIdInvalid) |
| 8607 | return child; |
| 8586 | 8608 | if (child.id != ConstCastResultIdOk) { |
| 8587 | 8609 | result.id = ConstCastResultIdSliceChild; |
| 8588 | 8610 | result.data.slice_mismatch = allocate_nonzero<ConstCastSliceMismatch>(1); |
| ... | ... | @@ -8598,6 +8620,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8598 | 8620 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) { |
| 8599 | 8621 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, |
| 8600 | 8622 | actual_type->data.maybe.child_type, source_node, wanted_is_mutable); |
| 8623 | if (child.id == ConstCastResultIdInvalid) |
| 8624 | return child; |
| 8601 | 8625 | if (child.id != ConstCastResultIdOk) { |
| 8602 | 8626 | result.id = ConstCastResultIdOptionalChild; |
| 8603 | 8627 | result.data.optional = allocate_nonzero<ConstCastOptionalMismatch>(1); |
| ... | ... | @@ -8612,6 +8636,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8612 | 8636 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) { |
| 8613 | 8637 | ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, |
| 8614 | 8638 | actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); |
| 8639 | if (payload_child.id == ConstCastResultIdInvalid) |
| 8640 | return payload_child; |
| 8615 | 8641 | if (payload_child.id != ConstCastResultIdOk) { |
| 8616 | 8642 | result.id = ConstCastResultIdErrorUnionPayload; |
| 8617 | 8643 | result.data.error_union_payload = allocate_nonzero<ConstCastErrUnionPayloadMismatch>(1); |
| ... | ... | @@ -8622,6 +8648,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8622 | 8648 | } |
| 8623 | 8649 | ConstCastOnly error_set_child = types_match_const_cast_only(ira, wanted_type->data.error_union.err_set_type, |
| 8624 | 8650 | actual_type->data.error_union.err_set_type, source_node, wanted_is_mutable); |
| 8651 | if (error_set_child.id == ConstCastResultIdInvalid) |
| 8652 | return error_set_child; |
| 8625 | 8653 | if (error_set_child.id != ConstCastResultIdOk) { |
| 8626 | 8654 | result.id = ConstCastResultIdErrorUnionErrorSet; |
| 8627 | 8655 | result.data.error_union_error_set = allocate_nonzero<ConstCastErrUnionErrSetMismatch>(1); |
| ... | ... | @@ -8709,6 +8737,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8709 | 8737 | { |
| 8710 | 8738 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, |
| 8711 | 8739 | actual_type->data.fn.fn_type_id.return_type, source_node, false); |
| 8740 | if (child.id == ConstCastResultIdInvalid) |
| 8741 | return child; |
| 8712 | 8742 | if (child.id != ConstCastResultIdOk) { |
| 8713 | 8743 | result.id = ConstCastResultIdFnReturnType; |
| 8714 | 8744 | result.data.return_type = allocate_nonzero<ConstCastOnly>(1); |
| ... | ... | @@ -8721,6 +8751,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8721 | 8751 | actual_type->data.fn.fn_type_id.async_allocator_type, |
| 8722 | 8752 | wanted_type->data.fn.fn_type_id.async_allocator_type, |
| 8723 | 8753 | source_node, false); |
| 8754 | if (child.id == ConstCastResultIdInvalid) |
| 8755 | return child; |
| 8724 | 8756 | if (child.id != ConstCastResultIdOk) { |
| 8725 | 8757 | result.id = ConstCastResultIdAsyncAllocatorType; |
| 8726 | 8758 | result.data.async_allocator_type = allocate_nonzero<ConstCastOnly>(1); |
| ... | ... | @@ -8745,6 +8777,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8745 | 8777 | |
| 8746 | 8778 | ConstCastOnly arg_child = types_match_const_cast_only(ira, actual_param_info->type, |
| 8747 | 8779 | expected_param_info->type, source_node, false); |
| 8780 | if (arg_child.id == ConstCastResultIdInvalid) |
| 8781 | return arg_child; |
| 8748 | 8782 | if (arg_child.id != ConstCastResultIdOk) { |
| 8749 | 8783 | result.id = ConstCastResultIdFnArg; |
| 8750 | 8784 | result.data.fn_arg.arg_index = i; |
| ... | ... | @@ -9238,7 +9272,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9238 | 9272 | if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion && |
| 9239 | 9273 | (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) |
| 9240 | 9274 | { |
| 9241 | | if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type))) |
| 9275 | if ((err = type_resolve(ira->codegen, cur_type, ResolveStatusZeroBitsKnown))) |
| 9242 | 9276 | return ira->codegen->builtin_types.entry_invalid; |
| 9243 | 9277 | if (cur_type->data.unionation.tag_type == prev_type) { |
| 9244 | 9278 | continue; |
| ... | ... | @@ -9248,7 +9282,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9248 | 9282 | if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion && |
| 9249 | 9283 | (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) |
| 9250 | 9284 | { |
| 9251 | | if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type))) |
| 9285 | if ((err = type_resolve(ira->codegen, prev_type, ResolveStatusZeroBitsKnown))) |
| 9252 | 9286 | return ira->codegen->builtin_types.entry_invalid; |
| 9253 | 9287 | if (prev_type->data.unionation.tag_type == cur_type) { |
| 9254 | 9288 | prev_inst = cur_inst; |
| ... | ... | @@ -9274,8 +9308,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9274 | 9308 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 9275 | 9309 | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 9276 | 9310 | true, false, PtrLenUnknown, |
| 9277 | | get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type), |
| 9278 | | 0, 0); |
| 9311 | 0, 0, 0); |
| 9279 | 9312 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); |
| 9280 | 9313 | if (err_set_type != nullptr) { |
| 9281 | 9314 | return get_error_union_type(ira->codegen, err_set_type, slice_type); |
| ... | ... | @@ -9472,7 +9505,16 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 9472 | 9505 | IrInstruction *value, ZigType *wanted_type) |
| 9473 | 9506 | { |
| 9474 | 9507 | assert(value->value.type->id == ZigTypeIdPointer); |
| 9475 | | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); |
| 9508 | |
| 9509 | Error err; |
| 9510 | |
| 9511 | if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type, |
| 9512 | ResolveStatusAlignmentKnown))) |
| 9513 | { |
| 9514 | return ira->codegen->invalid_instruction; |
| 9515 | } |
| 9516 | |
| 9517 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type)); |
| 9476 | 9518 | |
| 9477 | 9519 | if (instr_is_comptime(value)) { |
| 9478 | 9520 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node); |
| ... | ... | @@ -9500,7 +9542,15 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 9500 | 9542 | static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, |
| 9501 | 9543 | IrInstruction *value, ZigType *wanted_type) |
| 9502 | 9544 | { |
| 9503 | | wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); |
| 9545 | Error err; |
| 9546 | |
| 9547 | if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type, |
| 9548 | ResolveStatusAlignmentKnown))) |
| 9549 | { |
| 9550 | return ira->codegen->invalid_instruction; |
| 9551 | } |
| 9552 | |
| 9553 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type)); |
| 9504 | 9554 | |
| 9505 | 9555 | if (instr_is_comptime(value)) { |
| 9506 | 9556 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node); |
| ... | ... | @@ -9687,8 +9737,7 @@ static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9687 | 9737 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) |
| 9688 | 9738 | { |
| 9689 | 9739 | IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, |
| 9690 | | pointee_type, ptr_mut, ptr_is_const, ptr_is_volatile, |
| 9691 | | get_abi_alignment(ira->codegen, pointee_type)); |
| 9740 | pointee_type, ptr_mut, ptr_is_const, ptr_is_volatile, 0); |
| 9692 | 9741 | ir_link_new_instruction(const_instr, instruction); |
| 9693 | 9742 | return const_instr->value.type; |
| 9694 | 9743 | } |
| ... | ... | @@ -10005,20 +10054,24 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 10005 | 10054 | static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 10006 | 10055 | bool is_const, bool is_volatile) |
| 10007 | 10056 | { |
| 10057 | Error err; |
| 10058 | |
| 10008 | 10059 | if (type_is_invalid(value->value.type)) |
| 10009 | 10060 | return ira->codegen->invalid_instruction; |
| 10010 | 10061 | |
| 10062 | if ((err = type_resolve(ira->codegen, value->value.type, ResolveStatusZeroBitsKnown))) |
| 10063 | return ira->codegen->invalid_instruction; |
| 10064 | |
| 10011 | 10065 | if (instr_is_comptime(value)) { |
| 10012 | 10066 | ConstExprValue *val = ir_resolve_const(ira, value, UndefOk); |
| 10013 | 10067 | if (!val) |
| 10014 | 10068 | return ira->codegen->invalid_instruction; |
| 10015 | 10069 | return ir_get_const_ptr(ira, source_instruction, val, value->value.type, |
| 10016 | | ConstPtrMutComptimeConst, is_const, is_volatile, |
| 10017 | | get_abi_alignment(ira->codegen, value->value.type)); |
| 10070 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 10018 | 10071 | } |
| 10019 | 10072 | |
| 10020 | 10073 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, |
| 10021 | | is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0); |
| 10074 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); |
| 10022 | 10075 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, |
| 10023 | 10076 | source_instruction->source_node, value, is_const, is_volatile); |
| 10024 | 10077 | new_instruction->value.type = ptr_type; |
| ... | ... | @@ -10185,9 +10238,9 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 10185 | 10238 | return ira->codegen->invalid_instruction; |
| 10186 | 10239 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| 10187 | 10240 | assert(union_field != nullptr); |
| 10188 | | if ((err = type_ensure_zero_bits_known(ira->codegen, union_field->type_entry))) |
| 10241 | if ((err = type_resolve(ira->codegen, union_field->type_entry, ResolveStatusZeroBitsKnown))) |
| 10189 | 10242 | return ira->codegen->invalid_instruction; |
| 10190 | | if (!union_field->type_entry->zero_bits) { |
| 10243 | if (type_has_bits(union_field->type_entry)) { |
| 10191 | 10244 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 10192 | 10245 | union_field->enum_field->decl_index); |
| 10193 | 10246 | ErrorMsg *msg = ir_add_error(ira, source_instr, |
| ... | ... | @@ -10490,7 +10543,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 10490 | 10543 | ZigType *wanted_type) |
| 10491 | 10544 | { |
| 10492 | 10545 | assert(wanted_type->id == ZigTypeIdPointer); |
| 10493 | | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment); |
| 10546 | Error err; |
| 10547 | if ((err = type_resolve(ira->codegen, target->value.type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 10548 | return ira->codegen->invalid_instruction; |
| 10549 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type)); |
| 10494 | 10550 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 10495 | 10551 | assert(array_type->id == ZigTypeIdArray); |
| 10496 | 10552 | assert(array_type->data.array.len == 1); |
| ... | ... | @@ -10537,6 +10593,8 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10537 | 10593 | switch (cast_result->id) { |
| 10538 | 10594 | case ConstCastResultIdOk: |
| 10539 | 10595 | zig_unreachable(); |
| 10596 | case ConstCastResultIdInvalid: |
| 10597 | zig_unreachable(); |
| 10540 | 10598 | case ConstCastResultIdOptionalChild: { |
| 10541 | 10599 | ErrorMsg *msg = add_error_note(ira->codegen, parent_msg, source_node, |
| 10542 | 10600 | buf_sprintf("optional type child '%s' cannot cast into optional type child '%s'", |
| ... | ... | @@ -10636,6 +10694,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10636 | 10694 | // perfect match or non-const to const |
| 10637 | 10695 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type, |
| 10638 | 10696 | source_node, false); |
| 10697 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 10698 | return ira->codegen->invalid_instruction; |
| 10639 | 10699 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 10640 | 10700 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| 10641 | 10701 | } |
| ... | ... | @@ -10751,13 +10811,19 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10751 | 10811 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10752 | 10812 | actual_type->id == ZigTypeIdPointer && |
| 10753 | 10813 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10754 | | actual_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 10755 | | actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment && |
| 10756 | | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10757 | | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10758 | | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10814 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 10759 | 10815 | { |
| 10760 | | return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type); |
| 10816 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 10817 | return ira->codegen->invalid_instruction; |
| 10818 | if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 10819 | return ira->codegen->invalid_instruction; |
| 10820 | if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) && |
| 10821 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 10822 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10823 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10824 | { |
| 10825 | return ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_type); |
| 10826 | } |
| 10761 | 10827 | } |
| 10762 | 10828 | |
| 10763 | 10829 | // *[N]T to []T |
| ... | ... | @@ -10811,16 +10877,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10811 | 10877 | wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10812 | 10878 | actual_type->id == ZigTypeIdPointer && |
| 10813 | 10879 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10814 | | actual_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 10815 | | actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment && |
| 10816 | | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, |
| 10817 | | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10818 | | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10880 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 10819 | 10881 | { |
| 10820 | | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type); |
| 10821 | | if (type_is_invalid(cast1->value.type)) |
| 10882 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 10822 | 10883 | return ira->codegen->invalid_instruction; |
| 10823 | | return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type); |
| 10884 | if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 10885 | return ira->codegen->invalid_instruction; |
| 10886 | if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) && |
| 10887 | types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, |
| 10888 | actual_type->data.pointer.child_type->data.array.child_type, source_node, |
| 10889 | !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 10890 | { |
| 10891 | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 10892 | wanted_child_type); |
| 10893 | if (type_is_invalid(cast1->value.type)) |
| 10894 | return ira->codegen->invalid_instruction; |
| 10895 | return ir_analyze_maybe_wrap(ira, source_instr, cast1, wanted_type); |
| 10896 | } |
| 10824 | 10897 | } |
| 10825 | 10898 | } |
| 10826 | 10899 | |
| ... | ... | @@ -10963,7 +11036,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10963 | 11036 | |
| 10964 | 11037 | // cast from union to the enum type of the union |
| 10965 | 11038 | if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) { |
| 10966 | | if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type))) |
| 11039 | if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown))) |
| 10967 | 11040 | return ira->codegen->invalid_instruction; |
| 10968 | 11041 | |
| 10969 | 11042 | if (actual_type->data.unionation.tag_type == wanted_type) { |
| ... | ... | @@ -10976,7 +11049,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10976 | 11049 | (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10977 | 11050 | wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) |
| 10978 | 11051 | { |
| 10979 | | if ((err = type_ensure_zero_bits_known(ira->codegen, wanted_type))) |
| 11052 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown))) |
| 10980 | 11053 | return ira->codegen->invalid_instruction; |
| 10981 | 11054 | |
| 10982 | 11055 | if (wanted_type->data.unionation.tag_type == actual_type) { |
| ... | ... | @@ -10990,7 +11063,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10990 | 11063 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10991 | 11064 | union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) |
| 10992 | 11065 | { |
| 10993 | | if ((err = type_ensure_zero_bits_known(ira->codegen, union_type))) |
| 11066 | if ((err = type_resolve(ira->codegen, union_type, ResolveStatusZeroBitsKnown))) |
| 10994 | 11067 | return ira->codegen->invalid_instruction; |
| 10995 | 11068 | |
| 10996 | 11069 | if (union_type->data.unionation.tag_type == actual_type) { |
| ... | ... | @@ -11017,14 +11090,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11017 | 11090 | actual_type->data.pointer.child_type, source_node, |
| 11018 | 11091 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 11019 | 11092 | { |
| 11020 | | if (wanted_type->data.pointer.alignment > actual_type->data.pointer.alignment) { |
| 11093 | if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, |
| 11094 | ResolveStatusAlignmentKnown))) |
| 11095 | { |
| 11096 | return ira->codegen->invalid_instruction; |
| 11097 | } |
| 11098 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, |
| 11099 | ResolveStatusAlignmentKnown))) |
| 11100 | { |
| 11101 | return ira->codegen->invalid_instruction; |
| 11102 | } |
| 11103 | uint32_t wanted_align = get_ptr_align(ira->codegen, wanted_type); |
| 11104 | uint32_t actual_align = get_ptr_align(ira->codegen, actual_type); |
| 11105 | if (wanted_align > actual_align) { |
| 11021 | 11106 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 11022 | 11107 | add_error_note(ira->codegen, msg, value->source_node, |
| 11023 | | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&actual_type->name), |
| 11024 | | actual_type->data.pointer.alignment)); |
| 11108 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&actual_type->name), actual_align)); |
| 11025 | 11109 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 11026 | | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&wanted_type->name), |
| 11027 | | wanted_type->data.pointer.alignment)); |
| 11110 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&wanted_type->name), wanted_align)); |
| 11028 | 11111 | return ira->codegen->invalid_instruction; |
| 11029 | 11112 | } |
| 11030 | 11113 | return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type); |
| ... | ... | @@ -11036,7 +11119,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11036 | 11119 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 11037 | 11120 | actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 11038 | 11121 | { |
| 11039 | | if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type))) { |
| 11122 | if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown))) { |
| 11040 | 11123 | return ira->codegen->invalid_instruction; |
| 11041 | 11124 | } |
| 11042 | 11125 | if (!type_has_bits(actual_type)) { |
| ... | ... | @@ -11282,8 +11365,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11282 | 11365 | return nullptr; |
| 11283 | 11366 | |
| 11284 | 11367 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 11285 | | true, false, PtrLenUnknown, |
| 11286 | | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 11368 | true, false, PtrLenUnknown, 0, 0, 0); |
| 11287 | 11369 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 11288 | 11370 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 11289 | 11371 | if (type_is_invalid(casted_value->value.type)) |
| ... | ... | @@ -11573,8 +11655,6 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11573 | 11655 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 11574 | 11656 | if (type_is_invalid(resolved_type)) |
| 11575 | 11657 | return resolved_type; |
| 11576 | | if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type))) |
| 11577 | | return resolved_type; |
| 11578 | 11658 | |
| 11579 | 11659 | bool operator_allowed; |
| 11580 | 11660 | switch (resolved_type->id) { |
| ... | ... | @@ -11630,6 +11710,9 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11630 | 11710 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 11631 | 11711 | return ira->codegen->builtin_types.entry_invalid; |
| 11632 | 11712 | |
| 11713 | if ((err = type_resolve(ira->codegen, resolved_type, ResolveStatusZeroBitsKnown))) |
| 11714 | return resolved_type; |
| 11715 | |
| 11633 | 11716 | bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type); |
| 11634 | 11717 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { |
| 11635 | 11718 | ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| ... | ... | @@ -12316,7 +12399,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12316 | 12399 | out_array_val = out_val; |
| 12317 | 12400 | } else if (is_slice(op1_type) || is_slice(op2_type)) { |
| 12318 | 12401 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 12319 | | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); |
| 12402 | true, false, PtrLenUnknown, 0, 0, 0); |
| 12320 | 12403 | result_type = get_slice_type(ira->codegen, ptr_type); |
| 12321 | 12404 | out_array_val = create_const_vals(1); |
| 12322 | 12405 | out_array_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -12337,8 +12420,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12337 | 12420 | new_len += 1; // null byte |
| 12338 | 12421 | |
| 12339 | 12422 | // TODO make this `[*]null T` instead of `[*]T` |
| 12340 | | result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, |
| 12341 | | PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); |
| 12423 | result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0); |
| 12342 | 12424 | |
| 12343 | 12425 | out_array_val = create_const_vals(1); |
| 12344 | 12426 | out_array_val->special = ConstValSpecialStatic; |
| ... | ... | @@ -12563,7 +12645,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec |
| 12563 | 12645 | if (type_is_invalid(result_type)) { |
| 12564 | 12646 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12565 | 12647 | } else { |
| 12566 | | if ((err = type_ensure_zero_bits_known(ira->codegen, result_type))) { |
| 12648 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusZeroBitsKnown))) { |
| 12567 | 12649 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12568 | 12650 | } |
| 12569 | 12651 | } |
| ... | ... | @@ -12631,6 +12713,11 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec |
| 12631 | 12713 | } |
| 12632 | 12714 | |
| 12633 | 12715 | if (decl_var_instruction->align_value == nullptr) { |
| 12716 | if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) { |
| 12717 | var->value->type = ira->codegen->builtin_types.entry_invalid; |
| 12718 | decl_var_instruction->base.other = &decl_var_instruction->base; |
| 12719 | return ira->codegen->builtin_types.entry_void; |
| 12720 | } |
| 12634 | 12721 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); |
| 12635 | 12722 | } else { |
| 12636 | 12723 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->other, &var->align_bytes)) { |
| ... | ... | @@ -13100,7 +13187,6 @@ static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { |
| 13100 | 13187 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13101 | 13188 | ZigVar *var) |
| 13102 | 13189 | { |
| 13103 | | Error err; |
| 13104 | 13190 | while (var->next_var != nullptr) { |
| 13105 | 13191 | var = var->next_var; |
| 13106 | 13192 | } |
| ... | ... | @@ -13158,8 +13244,6 @@ no_mem_slot: |
| 13158 | 13244 | instruction->scope, instruction->source_node, var); |
| 13159 | 13245 | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type, |
| 13160 | 13246 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0); |
| 13161 | | if ((err = type_ensure_zero_bits_known(ira->codegen, var->value->type))) |
| 13162 | | return ira->codegen->invalid_instruction; |
| 13163 | 13247 | |
| 13164 | 13248 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 13165 | 13249 | var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| ... | ... | @@ -13356,8 +13440,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13356 | 13440 | IrInstruction *casted_new_stack = nullptr; |
| 13357 | 13441 | if (call_instruction->new_stack != nullptr) { |
| 13358 | 13442 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 13359 | | false, false, PtrLenUnknown, |
| 13360 | | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 13443 | false, false, PtrLenUnknown, 0, 0, 0); |
| 13361 | 13444 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 13362 | 13445 | IrInstruction *new_stack = call_instruction->new_stack->other; |
| 13363 | 13446 | if (type_is_invalid(new_stack->value.type)) |
| ... | ... | @@ -13536,7 +13619,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13536 | 13619 | inst_fn_type_id.return_type = specified_return_type; |
| 13537 | 13620 | } |
| 13538 | 13621 | |
| 13539 | | if ((err = type_ensure_zero_bits_known(ira->codegen, specified_return_type))) |
| 13622 | if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusZeroBitsKnown))) |
| 13540 | 13623 | return ira->codegen->builtin_types.entry_invalid; |
| 13541 | 13624 | |
| 13542 | 13625 | if (type_requires_comptime(specified_return_type)) { |
| ... | ... | @@ -14212,7 +14295,7 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 14212 | 14295 | ptr_type->data.pointer.child_type, |
| 14213 | 14296 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 14214 | 14297 | ptr_len, |
| 14215 | | ptr_type->data.pointer.alignment, |
| 14298 | ptr_type->data.pointer.explicit_alignment, |
| 14216 | 14299 | ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); |
| 14217 | 14300 | } |
| 14218 | 14301 | |
| ... | ... | @@ -14264,7 +14347,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14264 | 14347 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 14265 | 14348 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 14266 | 14349 | elem_ptr_instruction->ptr_len, |
| 14267 | | ptr_type->data.pointer.alignment, 0, 0); |
| 14350 | ptr_type->data.pointer.explicit_alignment, 0, 0); |
| 14268 | 14351 | } else { |
| 14269 | 14352 | uint64_t elem_val_scalar; |
| 14270 | 14353 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) |
| ... | ... | @@ -14336,7 +14419,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14336 | 14419 | |
| 14337 | 14420 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 14338 | 14421 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| 14339 | | uint64_t ptr_align = return_type->data.pointer.alignment; |
| 14422 | uint64_t ptr_align = get_ptr_align(ira->codegen, return_type); |
| 14340 | 14423 | if (instr_is_comptime(casted_elem_index)) { |
| 14341 | 14424 | uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint); |
| 14342 | 14425 | if (array_type->id == ZigTypeIdArray) { |
| ... | ... | @@ -14653,9 +14736,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14653 | 14736 | } |
| 14654 | 14737 | |
| 14655 | 14738 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 14656 | | is_const, is_volatile, |
| 14657 | | PtrLenSingle, |
| 14658 | | get_abi_alignment(ira->codegen, field_type), 0, 0); |
| 14739 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); |
| 14659 | 14740 | |
| 14660 | 14741 | IrInstruction *result = ir_get_const(ira, source_instr); |
| 14661 | 14742 | ConstExprValue *const_val = &result->value; |
| ... | ... | @@ -14669,7 +14750,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14669 | 14750 | |
| 14670 | 14751 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field); |
| 14671 | 14752 | result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, |
| 14672 | | PtrLenSingle, get_abi_alignment(ira->codegen, field->type_entry), 0, 0); |
| 14753 | PtrLenSingle, 0, 0, 0); |
| 14673 | 14754 | return result; |
| 14674 | 14755 | } else { |
| 14675 | 14756 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, |
| ... | ... | @@ -15002,9 +15083,14 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15002 | 15083 | } else if (buf_eql_str(field_name, "alignment")) { |
| 15003 | 15084 | bool ptr_is_const = true; |
| 15004 | 15085 | bool ptr_is_volatile = false; |
| 15086 | if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type, |
| 15087 | ResolveStatusAlignmentKnown))) |
| 15088 | { |
| 15089 | return ira->codegen->builtin_types.entry_invalid; |
| 15090 | } |
| 15005 | 15091 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 15006 | 15092 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, |
| 15007 | | child_type->data.pointer.alignment, false), |
| 15093 | get_ptr_align(ira->codegen, child_type), false), |
| 15008 | 15094 | ira->codegen->builtin_types.entry_num_lit_int, |
| 15009 | 15095 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 15010 | 15096 | } else { |
| ... | ... | @@ -15461,7 +15547,7 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15461 | 15547 | IrInstructionSliceType *slice_type_instruction) |
| 15462 | 15548 | { |
| 15463 | 15549 | Error err; |
| 15464 | | uint32_t align_bytes; |
| 15550 | uint32_t align_bytes = 0; |
| 15465 | 15551 | if (slice_type_instruction->align_value != nullptr) { |
| 15466 | 15552 | if (!ir_resolve_align(ira, slice_type_instruction->align_value->other, &align_bytes)) |
| 15467 | 15553 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15471,12 +15557,6 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15471 | 15557 | if (type_is_invalid(child_type)) |
| 15472 | 15558 | return ira->codegen->builtin_types.entry_invalid; |
| 15473 | 15559 | |
| 15474 | | if (slice_type_instruction->align_value == nullptr) { |
| 15475 | | if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) |
| 15476 | | return ira->codegen->builtin_types.entry_invalid; |
| 15477 | | align_bytes = get_abi_alignment(ira->codegen, child_type); |
| 15478 | | } |
| 15479 | | |
| 15480 | 15560 | bool is_const = slice_type_instruction->is_const; |
| 15481 | 15561 | bool is_volatile = slice_type_instruction->is_volatile; |
| 15482 | 15562 | |
| ... | ... | @@ -15511,7 +15591,7 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15511 | 15591 | case ZigTypeIdBoundFn: |
| 15512 | 15592 | case ZigTypeIdPromise: |
| 15513 | 15593 | { |
| 15514 | | if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) |
| 15594 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) |
| 15515 | 15595 | return ira->codegen->builtin_types.entry_invalid; |
| 15516 | 15596 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15517 | 15597 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); |
| ... | ... | @@ -15751,9 +15831,7 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15751 | 15831 | } |
| 15752 | 15832 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 15753 | 15833 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15754 | | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 15755 | | PtrLenSingle, |
| 15756 | | get_abi_alignment(ira->codegen, child_type), 0, 0); |
| 15834 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0); |
| 15757 | 15835 | |
| 15758 | 15836 | if (instr_is_comptime(value)) { |
| 15759 | 15837 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | ... | @@ -16123,7 +16201,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16123 | 16201 | return tag_type; |
| 16124 | 16202 | } |
| 16125 | 16203 | case ZigTypeIdEnum: { |
| 16126 | | if ((err = type_ensure_zero_bits_known(ira->codegen, target_type))) |
| 16204 | if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown))) |
| 16127 | 16205 | return ira->codegen->builtin_types.entry_invalid; |
| 16128 | 16206 | if (target_type->data.enumeration.src_field_count < 2) { |
| 16129 | 16207 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| ... | ... | @@ -16352,7 +16430,7 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc |
| 16352 | 16430 | if (casted_field_value == ira->codegen->invalid_instruction) |
| 16353 | 16431 | return ira->codegen->builtin_types.entry_invalid; |
| 16354 | 16432 | |
| 16355 | | if ((err = type_ensure_zero_bits_known(ira->codegen, casted_field_value->value.type))) |
| 16433 | if ((err = type_resolve(ira->codegen, casted_field_value->value.type, ResolveStatusZeroBitsKnown))) |
| 16356 | 16434 | return ira->codegen->builtin_types.entry_invalid; |
| 16357 | 16435 | |
| 16358 | 16436 | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope); |
| ... | ... | @@ -16752,7 +16830,7 @@ static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErr |
| 16752 | 16830 | return ira->codegen->builtin_types.entry_invalid; |
| 16753 | 16831 | |
| 16754 | 16832 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16755 | | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 16833 | true, false, PtrLenUnknown, 0, 0, 0); |
| 16756 | 16834 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16757 | 16835 | if (casted_value->value.special == ConstValSpecialStatic) { |
| 16758 | 16836 | ErrorTableEntry *err = casted_value->value.data.x_err_set; |
| ... | ... | @@ -16779,7 +16857,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi |
| 16779 | 16857 | assert(target->value.type->id == ZigTypeIdEnum); |
| 16780 | 16858 | |
| 16781 | 16859 | if (instr_is_comptime(target)) { |
| 16782 | | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) |
| 16860 | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 16783 | 16861 | return ira->codegen->builtin_types.entry_invalid; |
| 16784 | 16862 | TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); |
| 16785 | 16863 | ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name); |
| ... | ... | @@ -16794,8 +16872,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi |
| 16794 | 16872 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 16795 | 16873 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16796 | 16874 | true, false, PtrLenUnknown, |
| 16797 | | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), |
| 16798 | | 0, 0); |
| 16875 | 0, 0, 0); |
| 16799 | 16876 | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16800 | 16877 | return result->value.type; |
| 16801 | 16878 | } |
| ... | ... | @@ -17158,8 +17235,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17158 | 17235 | ZigType *u8_ptr = get_pointer_to_type_extra( |
| 17159 | 17236 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 17160 | 17237 | true, false, PtrLenUnknown, |
| 17161 | | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), |
| 17162 | | 0, 0); |
| 17238 | 0, 0, 0); |
| 17163 | 17239 | fn_def_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); |
| 17164 | 17240 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { |
| 17165 | 17241 | fn_def_fields[6].data.x_optional = create_const_vals(1); |
| ... | ... | @@ -17279,7 +17355,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 17279 | 17355 | ensure_field_index(result->type, "alignment", 3); |
| 17280 | 17356 | fields[3].special = ConstValSpecialStatic; |
| 17281 | 17357 | fields[3].type = get_int_type(ira->codegen, false, 29); |
| 17282 | | bigint_init_unsigned(&fields[3].data.x_bigint, attrs_type->data.pointer.alignment); |
| 17358 | bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type)); |
| 17283 | 17359 | // child: type |
| 17284 | 17360 | ensure_field_index(result->type, "child", 4); |
| 17285 | 17361 | fields[4].special = ConstValSpecialStatic; |
| ... | ... | @@ -18369,7 +18445,21 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio |
| 18369 | 18445 | return dest_type; |
| 18370 | 18446 | } |
| 18371 | 18447 | |
| 18448 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) { |
| 18449 | Error err; |
| 18450 | |
| 18451 | if (ty->id == ZigTypeIdPointer) { |
| 18452 | if ((err = type_resolve(ira->codegen, ty->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 18453 | return err; |
| 18454 | } |
| 18455 | |
| 18456 | *result_align = get_ptr_align(ira->codegen, ty); |
| 18457 | return ErrorNone; |
| 18458 | } |
| 18459 | |
| 18372 | 18460 | static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| 18461 | Error err; |
| 18462 | |
| 18373 | 18463 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); |
| 18374 | 18464 | if (type_is_invalid(dest_child_type)) |
| 18375 | 18465 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18384,15 +18474,23 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18384 | 18474 | if (target->value.type->id == ZigTypeIdPointer) { |
| 18385 | 18475 | src_ptr_const = target->value.type->data.pointer.is_const; |
| 18386 | 18476 | src_ptr_volatile = target->value.type->data.pointer.is_volatile; |
| 18387 | | src_ptr_align = target->value.type->data.pointer.alignment; |
| 18477 | |
| 18478 | if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) |
| 18479 | return ira->codegen->builtin_types.entry_invalid; |
| 18388 | 18480 | } else if (is_slice(target->value.type)) { |
| 18389 | 18481 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18390 | 18482 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 18391 | 18483 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 18392 | | src_ptr_align = src_ptr_type->data.pointer.alignment; |
| 18484 | |
| 18485 | if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align))) |
| 18486 | return ira->codegen->builtin_types.entry_invalid; |
| 18393 | 18487 | } else { |
| 18394 | 18488 | src_ptr_const = true; |
| 18395 | 18489 | src_ptr_volatile = false; |
| 18490 | |
| 18491 | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusAlignmentKnown))) |
| 18492 | return ira->codegen->builtin_types.entry_invalid; |
| 18493 | |
| 18396 | 18494 | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); |
| 18397 | 18495 | } |
| 18398 | 18496 | |
| ... | ... | @@ -18450,6 +18548,8 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18450 | 18548 | } |
| 18451 | 18549 | |
| 18452 | 18550 | static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| 18551 | Error err; |
| 18552 | |
| 18453 | 18553 | IrInstruction *target = instruction->target->other; |
| 18454 | 18554 | if (type_is_invalid(target->value.type)) |
| 18455 | 18555 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18462,9 +18562,13 @@ static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToB |
| 18462 | 18562 | |
| 18463 | 18563 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18464 | 18564 | |
| 18565 | uint32_t alignment; |
| 18566 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| 18567 | return ira->codegen->builtin_types.entry_invalid; |
| 18568 | |
| 18465 | 18569 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 18466 | 18570 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, |
| 18467 | | src_ptr_type->data.pointer.alignment, 0, 0); |
| 18571 | alignment, 0, 0); |
| 18468 | 18572 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 18469 | 18573 | |
| 18470 | 18574 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); |
| ... | ... | @@ -18622,6 +18726,8 @@ static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoo |
| 18622 | 18726 | } |
| 18623 | 18727 | |
| 18624 | 18728 | static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| 18729 | Error err; |
| 18730 | |
| 18625 | 18731 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18626 | 18732 | if (type_is_invalid(dest_ptr->value.type)) |
| 18627 | 18733 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18640,8 +18746,13 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18640 | 18746 | |
| 18641 | 18747 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18642 | 18748 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18643 | | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? |
| 18644 | | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18749 | uint32_t dest_align; |
| 18750 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 18751 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 18752 | return ira->codegen->builtin_types.entry_invalid; |
| 18753 | } else { |
| 18754 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 18755 | } |
| 18645 | 18756 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 18646 | 18757 | PtrLenUnknown, dest_align, 0, 0); |
| 18647 | 18758 | |
| ... | ... | @@ -18714,6 +18825,8 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18714 | 18825 | } |
| 18715 | 18826 | |
| 18716 | 18827 | static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| 18828 | Error err; |
| 18829 | |
| 18717 | 18830 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18718 | 18831 | if (type_is_invalid(dest_ptr->value.type)) |
| 18719 | 18832 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -18733,10 +18846,22 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 18733 | 18846 | dest_uncasted_type->data.pointer.is_volatile; |
| 18734 | 18847 | bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && |
| 18735 | 18848 | src_uncasted_type->data.pointer.is_volatile; |
| 18736 | | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? |
| 18737 | | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18738 | | uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ? |
| 18739 | | src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); |
| 18849 | |
| 18850 | uint32_t dest_align; |
| 18851 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 18852 | if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align))) |
| 18853 | return ira->codegen->builtin_types.entry_invalid; |
| 18854 | } else { |
| 18855 | dest_align = get_abi_alignment(ira->codegen, u8); |
| 18856 | } |
| 18857 | |
| 18858 | uint32_t src_align; |
| 18859 | if (src_uncasted_type->id == ZigTypeIdPointer) { |
| 18860 | if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align))) |
| 18861 | return ira->codegen->builtin_types.entry_invalid; |
| 18862 | } else { |
| 18863 | src_align = get_abi_alignment(ira->codegen, u8); |
| 18864 | } |
| 18740 | 18865 | |
| 18741 | 18866 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18742 | 18867 | ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| ... | ... | @@ -18881,17 +19006,13 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 18881 | 19006 | ZigType *return_type; |
| 18882 | 19007 | |
| 18883 | 19008 | if (array_type->id == ZigTypeIdArray) { |
| 18884 | | uint32_t byte_alignment = ptr_type->data.pointer.alignment; |
| 18885 | | if (array_type->data.array.len == 0 && byte_alignment == 0) { |
| 18886 | | byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); |
| 18887 | | } |
| 18888 | 19009 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 18889 | 19010 | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 18890 | 19011 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, |
| 18891 | 19012 | ptr_type->data.pointer.is_const || is_comptime_const, |
| 18892 | 19013 | ptr_type->data.pointer.is_volatile, |
| 18893 | 19014 | PtrLenUnknown, |
| 18894 | | byte_alignment, 0, 0); |
| 19015 | ptr_type->data.pointer.explicit_alignment, 0, 0); |
| 18895 | 19016 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18896 | 19017 | } else if (array_type->id == ZigTypeIdPointer) { |
| 18897 | 19018 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| ... | ... | @@ -18901,7 +19022,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 18901 | 19022 | main_type->data.pointer.child_type, |
| 18902 | 19023 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18903 | 19024 | PtrLenUnknown, |
| 18904 | | array_type->data.pointer.alignment, 0, 0); |
| 19025 | array_type->data.pointer.explicit_alignment, 0, 0); |
| 18905 | 19026 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18906 | 19027 | } else { |
| 18907 | 19028 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); |
| ... | ... | @@ -18911,7 +19032,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 18911 | 19032 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, |
| 18912 | 19033 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18913 | 19034 | PtrLenUnknown, |
| 18914 | | array_type->data.pointer.alignment, 0, 0); |
| 19035 | array_type->data.pointer.explicit_alignment, 0, 0); |
| 18915 | 19036 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18916 | 19037 | if (!end) { |
| 18917 | 19038 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); |
| ... | ... | @@ -19292,7 +19413,7 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli |
| 19292 | 19413 | return ira->codegen->builtin_types.entry_invalid; |
| 19293 | 19414 | ZigType *type_entry = ir_resolve_type(ira, type_value); |
| 19294 | 19415 | |
| 19295 | | if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry))) |
| 19416 | if ((err = type_resolve(ira->codegen, type_entry, ResolveStatusAlignmentKnown))) |
| 19296 | 19417 | return ira->codegen->builtin_types.entry_invalid; |
| 19297 | 19418 | |
| 19298 | 19419 | switch (type_entry->id) { |
| ... | ... | @@ -19336,6 +19457,8 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli |
| 19336 | 19457 | } |
| 19337 | 19458 | |
| 19338 | 19459 | static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| 19460 | Error err; |
| 19461 | |
| 19339 | 19462 | IrInstruction *type_value = instruction->type_value->other; |
| 19340 | 19463 | if (type_is_invalid(type_value->value.type)) |
| 19341 | 19464 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -19379,10 +19502,13 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction |
| 19379 | 19502 | |
| 19380 | 19503 | ZigType *expected_ptr_type; |
| 19381 | 19504 | if (result_ptr->value.type->id == ZigTypeIdPointer) { |
| 19505 | uint32_t alignment; |
| 19506 | if ((err = resolve_ptr_align(ira, result_ptr->value.type, &alignment))) |
| 19507 | return ira->codegen->builtin_types.entry_invalid; |
| 19382 | 19508 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 19383 | 19509 | false, result_ptr->value.type->data.pointer.is_volatile, |
| 19384 | 19510 | PtrLenSingle, |
| 19385 | | result_ptr->value.type->data.pointer.alignment, 0, 0); |
| 19511 | alignment, 0, 0); |
| 19386 | 19512 | } else { |
| 19387 | 19513 | expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); |
| 19388 | 19514 | } |
| ... | ... | @@ -19544,8 +19670,7 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19544 | 19670 | } |
| 19545 | 19671 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 19546 | 19672 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 19547 | | PtrLenSingle, |
| 19548 | | get_abi_alignment(ira->codegen, payload_type), 0, 0); |
| 19673 | PtrLenSingle, 0, 0, 0); |
| 19549 | 19674 | if (instr_is_comptime(value)) { |
| 19550 | 19675 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19551 | 19676 | if (!ptr_val) |
| ... | ... | @@ -19624,7 +19749,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP |
| 19624 | 19749 | ZigType *param_type = ir_resolve_type(ira, param_type_value); |
| 19625 | 19750 | if (type_is_invalid(param_type)) |
| 19626 | 19751 | return ira->codegen->builtin_types.entry_invalid; |
| 19627 | | if ((err = type_ensure_zero_bits_known(ira->codegen, param_type))) |
| 19752 | if ((err = type_resolve(ira->codegen, param_type, ResolveStatusZeroBitsKnown))) |
| 19628 | 19753 | return ira->codegen->builtin_types.entry_invalid; |
| 19629 | 19754 | if (type_requires_comptime(param_type)) { |
| 19630 | 19755 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| ... | ... | @@ -19899,7 +20024,7 @@ static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic |
| 19899 | 20024 | } |
| 19900 | 20025 | |
| 19901 | 20026 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 19902 | | true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); |
| 20027 | true, false, PtrLenUnknown, 0, 0, 0); |
| 19903 | 20028 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 19904 | 20029 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 19905 | 20030 | if (type_is_invalid(casted_msg->value.type)) |
| ... | ... | @@ -19912,6 +20037,8 @@ static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic |
| 19912 | 20037 | } |
| 19913 | 20038 | |
| 19914 | 20039 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| 20040 | Error err; |
| 20041 | |
| 19915 | 20042 | ZigType *target_type = target->value.type; |
| 19916 | 20043 | assert(!type_is_invalid(target_type)); |
| 19917 | 20044 | |
| ... | ... | @@ -19920,7 +20047,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19920 | 20047 | |
| 19921 | 20048 | if (target_type->id == ZigTypeIdPointer) { |
| 19922 | 20049 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); |
| 19923 | | old_align_bytes = target_type->data.pointer.alignment; |
| 20050 | if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes))) |
| 20051 | return ira->codegen->invalid_instruction; |
| 19924 | 20052 | } else if (target_type->id == ZigTypeIdFn) { |
| 19925 | 20053 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; |
| 19926 | 20054 | old_align_bytes = fn_type_id.alignment; |
| ... | ... | @@ -19930,7 +20058,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19930 | 20058 | target_type->data.maybe.child_type->id == ZigTypeIdPointer) |
| 19931 | 20059 | { |
| 19932 | 20060 | ZigType *ptr_type = target_type->data.maybe.child_type; |
| 19933 | | old_align_bytes = ptr_type->data.pointer.alignment; |
| 20061 | if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes))) |
| 20062 | return ira->codegen->invalid_instruction; |
| 19934 | 20063 | ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); |
| 19935 | 20064 | |
| 19936 | 20065 | result_type = get_optional_type(ira->codegen, better_ptr_type); |
| ... | ... | @@ -19944,7 +20073,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19944 | 20073 | result_type = get_optional_type(ira->codegen, fn_type); |
| 19945 | 20074 | } else if (is_slice(target_type)) { |
| 19946 | 20075 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; |
| 19947 | | old_align_bytes = slice_ptr_type->data.pointer.alignment; |
| 20076 | if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes))) |
| 20077 | return ira->codegen->invalid_instruction; |
| 19948 | 20078 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| 19949 | 20079 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 19950 | 20080 | } else { |
| ... | ... | @@ -20023,8 +20153,13 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr |
| 20023 | 20153 | return dest_type; |
| 20024 | 20154 | } |
| 20025 | 20155 | |
| 20026 | | uint32_t src_align_bytes = get_ptr_align(ira->codegen, src_type); |
| 20027 | | uint32_t dest_align_bytes = get_ptr_align(ira->codegen, dest_type); |
| 20156 | uint32_t src_align_bytes; |
| 20157 | if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes))) |
| 20158 | return ira->codegen->builtin_types.entry_invalid; |
| 20159 | |
| 20160 | uint32_t dest_align_bytes; |
| 20161 | if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes))) |
| 20162 | return ira->codegen->builtin_types.entry_invalid; |
| 20028 | 20163 | |
| 20029 | 20164 | if (dest_align_bytes > src_align_bytes) { |
| 20030 | 20165 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cast increases pointer alignment")); |
| ... | ... | @@ -20041,7 +20176,7 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr |
| 20041 | 20176 | |
| 20042 | 20177 | // Keep the bigger alignment, it can only help- |
| 20043 | 20178 | // unless the target is zero bits. |
| 20044 | | if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) |
| 20179 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 20045 | 20180 | return ira->codegen->builtin_types.entry_invalid; |
| 20046 | 20181 | |
| 20047 | 20182 | IrInstruction *result; |
| ... | ... | @@ -20289,7 +20424,7 @@ static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionI |
| 20289 | 20424 | return ira->codegen->builtin_types.entry_invalid; |
| 20290 | 20425 | } |
| 20291 | 20426 | |
| 20292 | | if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) |
| 20427 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 20293 | 20428 | return ira->codegen->builtin_types.entry_invalid; |
| 20294 | 20429 | if (!type_has_bits(dest_type)) { |
| 20295 | 20430 | ir_add_error(ira, dest_type_value, |
| ... | ... | @@ -20440,12 +20575,15 @@ static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtr |
| 20440 | 20575 | if (instruction->align_value != nullptr) { |
| 20441 | 20576 | if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes)) |
| 20442 | 20577 | return ira->codegen->builtin_types.entry_invalid; |
| 20578 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) |
| 20579 | return ira->codegen->builtin_types.entry_invalid; |
| 20443 | 20580 | } else { |
| 20444 | | if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) |
| 20581 | if ((err = type_resolve(ira->codegen, child_type, ResolveStatusZeroBitsKnown))) |
| 20445 | 20582 | return ira->codegen->builtin_types.entry_invalid; |
| 20446 | | align_bytes = get_abi_alignment(ira->codegen, child_type); |
| 20583 | align_bytes = 0; |
| 20447 | 20584 | } |
| 20448 | 20585 | |
| 20586 | |
| 20449 | 20587 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20450 | 20588 | out_val->data.x_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 20451 | 20589 | instruction->is_const, instruction->is_volatile, |
| ... | ... | @@ -21089,7 +21227,7 @@ static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstruction |
| 21089 | 21227 | return ira->codegen->builtin_types.entry_invalid; |
| 21090 | 21228 | } |
| 21091 | 21229 | |
| 21092 | | if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) |
| 21230 | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 21093 | 21231 | return ira->codegen->builtin_types.entry_invalid; |
| 21094 | 21232 | |
| 21095 | 21233 | ZigType *tag_type = target->value.type->data.enumeration.tag_int_type; |
| ... | ... | @@ -21112,7 +21250,7 @@ static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstruction |
| 21112 | 21250 | return ira->codegen->builtin_types.entry_invalid; |
| 21113 | 21251 | } |
| 21114 | 21252 | |
| 21115 | | if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) |
| 21253 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| 21116 | 21254 | return ira->codegen->builtin_types.entry_invalid; |
| 21117 | 21255 | |
| 21118 | 21256 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |