| ... | @@ -40,6 +40,7 @@ struct IrAnalyze { | ... | @@ -40,6 +40,7 @@ struct IrAnalyze { |
| 40 | | 40 | |
| 41 | enum ConstCastResultId { | 41 | enum ConstCastResultId { |
| 42 | ConstCastResultIdOk, | 42 | ConstCastResultIdOk, |
| | 43 | ConstCastResultIdInvalid, |
| 43 | ConstCastResultIdErrSet, | 44 | ConstCastResultIdErrSet, |
| 44 | ConstCastResultIdErrSetGlobal, | 45 | ConstCastResultIdErrSetGlobal, |
| 45 | ConstCastResultIdPointerChild, | 46 | ConstCastResultIdPointerChild, |
| ... | @@ -7490,8 +7491,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec | ... | @@ -7490,8 +7491,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7490 | if (type_has_bits(return_type)) { | 7491 | if (type_has_bits(return_type)) { |
| 7491 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, | 7492 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, |
| 7492 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, | 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 | false, false, PtrLenUnknown, 0, 0, 0)); |
| 7494 | 0, 0)); | | |
| 7495 | IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr); | 7495 | IrInstruction *result_ptr = ir_build_load_ptr(irb, scope, node, irb->exec->coro_result_ptr_field_ptr); |
| 7496 | IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, result_ptr); | 7496 | IrInstruction *result_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, result_ptr); |
| 7497 | IrInstruction *return_value_ptr_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, | 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,8 +7544,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 7544 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); | 7544 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); |
| 7545 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, | 7545 | IrInstruction *u8_ptr_type_unknown_len = ir_build_const_type(irb, scope, node, |
| 7546 | get_pointer_to_type_extra(irb->codegen, irb->codegen->builtin_types.entry_u8, | 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), | 7547 | false, false, PtrLenUnknown, 0, 0, 0)); |
| 7548 | 0, 0)); | | |
| 7549 | IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, coro_mem_ptr_maybe); | 7548 | IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type_unknown_len, coro_mem_ptr_maybe); |
| 7550 | IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false); | 7549 | IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false); |
| 7551 | IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var); | 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,6 +8515,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8516 | ConstCastOnly result = {}; | 8515 | ConstCastOnly result = {}; |
| 8517 | result.id = ConstCastResultIdOk; | 8516 | result.id = ConstCastResultIdOk; |
| 8518 | | 8517 | |
| | 8518 | Error err; |
| | 8519 | |
| 8519 | if (wanted_type == actual_type) | 8520 | if (wanted_type == actual_type) |
| 8520 | return result; | 8521 | return result; |
| 8521 | | 8522 | |
| ... | @@ -8528,6 +8529,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -8528,6 +8529,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8528 | { | 8529 | { |
| 8529 | ConstCastOnly child = types_match_const_cast_only(ira, | 8530 | ConstCastOnly child = types_match_const_cast_only(ira, |
| 8530 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); | 8531 | wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); |
| | 8532 | if (child.id == ConstCastResultIdInvalid) |
| | 8533 | return child; |
| 8531 | if (child.id != ConstCastResultIdOk) { | 8534 | if (child.id != ConstCastResultIdOk) { |
| 8532 | result.id = ConstCastResultIdNullWrapPtr; | 8535 | result.id = ConstCastResultIdNullWrapPtr; |
| 8533 | result.data.null_wrap_ptr_child = allocate_nonzero<ConstCastOnly>(1); | 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,7 +8547,6 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8544 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && | 8547 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8545 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) | 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 | return result; | 8550 | return result; |
| 8549 | } | 8551 | } |
| 8550 | | 8552 | |
| ... | @@ -8552,6 +8554,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -8552,6 +8554,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8552 | if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { | 8554 | if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { |
| 8553 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, | 8555 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 8554 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); | 8556 | actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); |
| | 8557 | if (child.id == ConstCastResultIdInvalid) |
| | 8558 | return child; |
| 8555 | if (child.id != ConstCastResultIdOk) { | 8559 | if (child.id != ConstCastResultIdOk) { |
| 8556 | result.id = ConstCastResultIdPointerChild; | 8560 | result.id = ConstCastResultIdPointerChild; |
| 8557 | result.data.pointer_mismatch = allocate_nonzero<ConstCastPointerMismatch>(1); | 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,12 +8564,20 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8560 | result.data.pointer_mismatch->actual_child = actual_type->data.pointer.child_type; | 8564 | result.data.pointer_mismatch->actual_child = actual_type->data.pointer.child_type; |
| 8561 | return result; | 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 | if ((actual_type->data.pointer.ptr_len == wanted_type->data.pointer.ptr_len) && | 8575 | if ((actual_type->data.pointer.ptr_len == wanted_type->data.pointer.ptr_len) && |
| 8564 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && | 8576 | (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && |
| 8565 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile) && | 8577 | (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile) && |
| 8566 | actual_type->data.pointer.bit_offset == wanted_type->data.pointer.bit_offset && | 8578 | actual_type->data.pointer.bit_offset == wanted_type->data.pointer.bit_offset && |
| 8567 | actual_type->data.pointer.unaligned_bit_count == wanted_type->data.pointer.unaligned_bit_count && | 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 | return result; | 8582 | return result; |
| 8571 | } | 8583 | } |
| ... | @@ -8575,14 +8587,24 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -8575,14 +8587,24 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8575 | if (is_slice(wanted_type) && is_slice(actual_type)) { | 8587 | if (is_slice(wanted_type) && is_slice(actual_type)) { |
| 8576 | ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; | 8588 | ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8577 | ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; | 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 | if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && | 8598 | if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && |
| 8579 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && | 8599 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && |
| 8580 | actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset && | 8600 | actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset && |
| 8581 | actual_ptr_type->data.pointer.unaligned_bit_count == wanted_ptr_type->data.pointer.unaligned_bit_count && | 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 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type, | 8604 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_ptr_type->data.pointer.child_type, |
| 8585 | actual_ptr_type->data.pointer.child_type, source_node, !wanted_ptr_type->data.pointer.is_const); | 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 | if (child.id != ConstCastResultIdOk) { | 8608 | if (child.id != ConstCastResultIdOk) { |
| 8587 | result.id = ConstCastResultIdSliceChild; | 8609 | result.id = ConstCastResultIdSliceChild; |
| 8588 | result.data.slice_mismatch = allocate_nonzero<ConstCastSliceMismatch>(1); | 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,6 +8620,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8598 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) { | 8620 | if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) { |
| 8599 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, | 8621 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, |
| 8600 | actual_type->data.maybe.child_type, source_node, wanted_is_mutable); | 8622 | actual_type->data.maybe.child_type, source_node, wanted_is_mutable); |
| | 8623 | if (child.id == ConstCastResultIdInvalid) |
| | 8624 | return child; |
| 8601 | if (child.id != ConstCastResultIdOk) { | 8625 | if (child.id != ConstCastResultIdOk) { |
| 8602 | result.id = ConstCastResultIdOptionalChild; | 8626 | result.id = ConstCastResultIdOptionalChild; |
| 8603 | result.data.optional = allocate_nonzero<ConstCastOptionalMismatch>(1); | 8627 | result.data.optional = allocate_nonzero<ConstCastOptionalMismatch>(1); |
| ... | @@ -8612,6 +8636,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -8612,6 +8636,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8612 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) { | 8636 | if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) { |
| 8613 | ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, | 8637 | ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, |
| 8614 | actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); | 8638 | actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); |
| | 8639 | if (payload_child.id == ConstCastResultIdInvalid) |
| | 8640 | return payload_child; |
| 8615 | if (payload_child.id != ConstCastResultIdOk) { | 8641 | if (payload_child.id != ConstCastResultIdOk) { |
| 8616 | result.id = ConstCastResultIdErrorUnionPayload; | 8642 | result.id = ConstCastResultIdErrorUnionPayload; |
| 8617 | result.data.error_union_payload = allocate_nonzero<ConstCastErrUnionPayloadMismatch>(1); | 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,6 +8648,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8622 | } | 8648 | } |
| 8623 | ConstCastOnly error_set_child = types_match_const_cast_only(ira, wanted_type->data.error_union.err_set_type, | 8649 | ConstCastOnly error_set_child = types_match_const_cast_only(ira, wanted_type->data.error_union.err_set_type, |
| 8624 | actual_type->data.error_union.err_set_type, source_node, wanted_is_mutable); | 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 | if (error_set_child.id != ConstCastResultIdOk) { | 8653 | if (error_set_child.id != ConstCastResultIdOk) { |
| 8626 | result.id = ConstCastResultIdErrorUnionErrorSet; | 8654 | result.id = ConstCastResultIdErrorUnionErrorSet; |
| 8627 | result.data.error_union_error_set = allocate_nonzero<ConstCastErrUnionErrSetMismatch>(1); | 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,6 +8737,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8709 | { | 8737 | { |
| 8710 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, | 8738 | ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, |
| 8711 | actual_type->data.fn.fn_type_id.return_type, source_node, false); | 8739 | actual_type->data.fn.fn_type_id.return_type, source_node, false); |
| | 8740 | if (child.id == ConstCastResultIdInvalid) |
| | 8741 | return child; |
| 8712 | if (child.id != ConstCastResultIdOk) { | 8742 | if (child.id != ConstCastResultIdOk) { |
| 8713 | result.id = ConstCastResultIdFnReturnType; | 8743 | result.id = ConstCastResultIdFnReturnType; |
| 8714 | result.data.return_type = allocate_nonzero<ConstCastOnly>(1); | 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,6 +8751,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8721 | actual_type->data.fn.fn_type_id.async_allocator_type, | 8751 | actual_type->data.fn.fn_type_id.async_allocator_type, |
| 8722 | wanted_type->data.fn.fn_type_id.async_allocator_type, | 8752 | wanted_type->data.fn.fn_type_id.async_allocator_type, |
| 8723 | source_node, false); | 8753 | source_node, false); |
| | 8754 | if (child.id == ConstCastResultIdInvalid) |
| | 8755 | return child; |
| 8724 | if (child.id != ConstCastResultIdOk) { | 8756 | if (child.id != ConstCastResultIdOk) { |
| 8725 | result.id = ConstCastResultIdAsyncAllocatorType; | 8757 | result.id = ConstCastResultIdAsyncAllocatorType; |
| 8726 | result.data.async_allocator_type = allocate_nonzero<ConstCastOnly>(1); | 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,6 +8777,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8745 | | 8777 | |
| 8746 | ConstCastOnly arg_child = types_match_const_cast_only(ira, actual_param_info->type, | 8778 | ConstCastOnly arg_child = types_match_const_cast_only(ira, actual_param_info->type, |
| 8747 | expected_param_info->type, source_node, false); | 8779 | expected_param_info->type, source_node, false); |
| | 8780 | if (arg_child.id == ConstCastResultIdInvalid) |
| | 8781 | return arg_child; |
| 8748 | if (arg_child.id != ConstCastResultIdOk) { | 8782 | if (arg_child.id != ConstCastResultIdOk) { |
| 8749 | result.id = ConstCastResultIdFnArg; | 8783 | result.id = ConstCastResultIdFnArg; |
| 8750 | result.data.fn_arg.arg_index = i; | 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,7 +9272,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9238 | if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion && | 9272 | if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion && |
| 9239 | (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) | 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 | return ira->codegen->builtin_types.entry_invalid; | 9276 | return ira->codegen->builtin_types.entry_invalid; |
| 9243 | if (cur_type->data.unionation.tag_type == prev_type) { | 9277 | if (cur_type->data.unionation.tag_type == prev_type) { |
| 9244 | continue; | 9278 | continue; |
| ... | @@ -9248,7 +9282,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -9248,7 +9282,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9248 | if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion && | 9282 | if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion && |
| 9249 | (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) | 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 | return ira->codegen->builtin_types.entry_invalid; | 9286 | return ira->codegen->builtin_types.entry_invalid; |
| 9253 | if (prev_type->data.unionation.tag_type == cur_type) { | 9287 | if (prev_type->data.unionation.tag_type == cur_type) { |
| 9254 | prev_inst = cur_inst; | 9288 | prev_inst = cur_inst; |
| ... | @@ -9274,8 +9308,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT | ... | @@ -9274,8 +9308,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 9274 | ZigType *ptr_type = get_pointer_to_type_extra( | 9308 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 9275 | ira->codegen, prev_inst->value.type->data.array.child_type, | 9309 | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 9276 | true, false, PtrLenUnknown, | 9310 | true, false, PtrLenUnknown, |
| 9277 | get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type), | 9311 | 0, 0, 0); |
| 9278 | 0, 0); | | |
| 9279 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); | 9312 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); |
| 9280 | if (err_set_type != nullptr) { | 9313 | if (err_set_type != nullptr) { |
| 9281 | return get_error_union_type(ira->codegen, err_set_type, slice_type); | 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,7 +9505,16 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 9472 | IrInstruction *value, ZigType *wanted_type) | 9505 | IrInstruction *value, ZigType *wanted_type) |
| 9473 | { | 9506 | { |
| 9474 | assert(value->value.type->id == ZigTypeIdPointer); | 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 | if (instr_is_comptime(value)) { | 9519 | if (instr_is_comptime(value)) { |
| 9478 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node); | 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,7 +9542,15 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, |
| 9500 | static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, | 9542 | static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, |
| 9501 | IrInstruction *value, ZigType *wanted_type) | 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 | if (instr_is_comptime(value)) { | 9555 | if (instr_is_comptime(value)) { |
| 9506 | ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node); | 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,8 +9737,7 @@ static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 9687 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) | 9737 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) |
| 9688 | { | 9738 | { |
| 9689 | IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, | 9739 | IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, |
| 9690 | pointee_type, ptr_mut, ptr_is_const, ptr_is_volatile, | 9740 | pointee_type, ptr_mut, ptr_is_const, ptr_is_volatile, 0); |
| 9691 | get_abi_alignment(ira->codegen, pointee_type)); | | |
| 9692 | ir_link_new_instruction(const_instr, instruction); | 9741 | ir_link_new_instruction(const_instr, instruction); |
| 9693 | return const_instr->value.type; | 9742 | return const_instr->value.type; |
| 9694 | } | 9743 | } |
| ... | @@ -10005,20 +10054,24 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so | ... | @@ -10005,20 +10054,24 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 10005 | static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, | 10054 | static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, |
| 10006 | bool is_const, bool is_volatile) | 10055 | bool is_const, bool is_volatile) |
| 10007 | { | 10056 | { |
| | 10057 | Error err; |
| | 10058 | |
| 10008 | if (type_is_invalid(value->value.type)) | 10059 | if (type_is_invalid(value->value.type)) |
| 10009 | return ira->codegen->invalid_instruction; | 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 | if (instr_is_comptime(value)) { | 10065 | if (instr_is_comptime(value)) { |
| 10012 | ConstExprValue *val = ir_resolve_const(ira, value, UndefOk); | 10066 | ConstExprValue *val = ir_resolve_const(ira, value, UndefOk); |
| 10013 | if (!val) | 10067 | if (!val) |
| 10014 | return ira->codegen->invalid_instruction; | 10068 | return ira->codegen->invalid_instruction; |
| 10015 | return ir_get_const_ptr(ira, source_instruction, val, value->value.type, | 10069 | return ir_get_const_ptr(ira, source_instruction, val, value->value.type, |
| 10016 | ConstPtrMutComptimeConst, is_const, is_volatile, | 10070 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 10017 | get_abi_alignment(ira->codegen, value->value.type)); | | |
| 10018 | } | 10071 | } |
| 10019 | | 10072 | |
| 10020 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, | 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 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, | 10075 | IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, |
| 10023 | source_instruction->source_node, value, is_const, is_volatile); | 10076 | source_instruction->source_node, value, is_const, is_volatile); |
| 10024 | new_instruction->value.type = ptr_type; | 10077 | new_instruction->value.type = ptr_type; |
| ... | @@ -10185,9 +10238,9 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so | ... | @@ -10185,9 +10238,9 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 10185 | return ira->codegen->invalid_instruction; | 10238 | return ira->codegen->invalid_instruction; |
| 10186 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); | 10239 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| 10187 | assert(union_field != nullptr); | 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 | return ira->codegen->invalid_instruction; | 10242 | return ira->codegen->invalid_instruction; |
| 10190 | if (!union_field->type_entry->zero_bits) { | 10243 | if (type_has_bits(union_field->type_entry)) { |
| 10191 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( | 10244 | AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at( |
| 10192 | union_field->enum_field->decl_index); | 10245 | union_field->enum_field->decl_index); |
| 10193 | ErrorMsg *msg = ir_add_error(ira, source_instr, | 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,7 +10543,10 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 10490 | ZigType *wanted_type) | 10543 | ZigType *wanted_type) |
| 10491 | { | 10544 | { |
| 10492 | assert(wanted_type->id == ZigTypeIdPointer); | 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 | ZigType *array_type = wanted_type->data.pointer.child_type; | 10550 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 10495 | assert(array_type->id == ZigTypeIdArray); | 10551 | assert(array_type->id == ZigTypeIdArray); |
| 10496 | assert(array_type->data.array.len == 1); | 10552 | assert(array_type->data.array.len == 1); |
| ... | @@ -10537,6 +10593,8 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa | ... | @@ -10537,6 +10593,8 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10537 | switch (cast_result->id) { | 10593 | switch (cast_result->id) { |
| 10538 | case ConstCastResultIdOk: | 10594 | case ConstCastResultIdOk: |
| 10539 | zig_unreachable(); | 10595 | zig_unreachable(); |
| | 10596 | case ConstCastResultIdInvalid: |
| | 10597 | zig_unreachable(); |
| 10540 | case ConstCastResultIdOptionalChild: { | 10598 | case ConstCastResultIdOptionalChild: { |
| 10541 | ErrorMsg *msg = add_error_note(ira->codegen, parent_msg, source_node, | 10599 | ErrorMsg *msg = add_error_note(ira->codegen, parent_msg, source_node, |
| 10542 | buf_sprintf("optional type child '%s' cannot cast into optional type child '%s'", | 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,6 +10694,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10636 | // perfect match or non-const to const | 10694 | // perfect match or non-const to const |
| 10637 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type, | 10695 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type, |
| 10638 | source_node, false); | 10696 | source_node, false); |
| | 10697 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| | 10698 | return ira->codegen->invalid_instruction; |
| 10639 | if (const_cast_result.id == ConstCastResultIdOk) { | 10699 | if (const_cast_result.id == ConstCastResultIdOk) { |
| 10640 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); | 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,13 +10811,19 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10751 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && | 10811 | wanted_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10752 | actual_type->id == ZigTypeIdPointer && | 10812 | actual_type->id == ZigTypeIdPointer && |
| 10753 | actual_type->data.pointer.ptr_len == PtrLenSingle && | 10813 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10754 | actual_type->data.pointer.child_type->id == ZigTypeIdArray && | 10814 | 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) | | |
| 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 | // *[N]T to []T | 10829 | // *[N]T to []T |
| ... | @@ -10811,16 +10877,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -10811,16 +10877,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10811 | wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && | 10877 | wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && |
| 10812 | actual_type->id == ZigTypeIdPointer && | 10878 | actual_type->id == ZigTypeIdPointer && |
| 10813 | actual_type->data.pointer.ptr_len == PtrLenSingle && | 10879 | actual_type->data.pointer.ptr_len == PtrLenSingle && |
| 10814 | actual_type->data.pointer.child_type->id == ZigTypeIdArray && | 10880 | 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) | | |
| 10819 | { | 10881 | { |
| 10820 | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, wanted_child_type); | 10882 | if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 10821 | if (type_is_invalid(cast1->value.type)) | | |
| 10822 | return ira->codegen->invalid_instruction; | 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,7 +11036,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10963 | | 11036 | |
| 10964 | // cast from union to the enum type of the union | 11037 | // cast from union to the enum type of the union |
| 10965 | if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) { | 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 | return ira->codegen->invalid_instruction; | 11040 | return ira->codegen->invalid_instruction; |
| 10968 | | 11041 | |
| 10969 | if (actual_type->data.unionation.tag_type == wanted_type) { | 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,7 +11049,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10976 | (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || | 11049 | (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10977 | wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) | 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 | return ira->codegen->invalid_instruction; | 11053 | return ira->codegen->invalid_instruction; |
| 10981 | | 11054 | |
| 10982 | if (wanted_type->data.unionation.tag_type == actual_type) { | 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,7 +11063,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 10990 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || | 11063 | if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || |
| 10991 | union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) | 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 | return ira->codegen->invalid_instruction; | 11067 | return ira->codegen->invalid_instruction; |
| 10995 | | 11068 | |
| 10996 | if (union_type->data.unionation.tag_type == actual_type) { | 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,14 +11090,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11017 | actual_type->data.pointer.child_type, source_node, | 11090 | actual_type->data.pointer.child_type, source_node, |
| 11018 | !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | 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 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); | 11106 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment")); |
| 11022 | add_error_note(ira->codegen, msg, value->source_node, | 11107 | add_error_note(ira->codegen, msg, value->source_node, |
| 11023 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&actual_type->name), | 11108 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&actual_type->name), actual_align)); |
| 11024 | actual_type->data.pointer.alignment)); | | |
| 11025 | add_error_note(ira->codegen, msg, source_instr->source_node, | 11109 | add_error_note(ira->codegen, msg, source_instr->source_node, |
| 11026 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&wanted_type->name), | 11110 | buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&wanted_type->name), wanted_align)); |
| 11027 | wanted_type->data.pointer.alignment)); | | |
| 11028 | return ira->codegen->invalid_instruction; | 11111 | return ira->codegen->invalid_instruction; |
| 11029 | } | 11112 | } |
| 11030 | return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type); | 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,7 +11119,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11036 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, | 11119 | types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, |
| 11037 | actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) | 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 | return ira->codegen->invalid_instruction; | 11123 | return ira->codegen->invalid_instruction; |
| 11041 | } | 11124 | } |
| 11042 | if (!type_has_bits(actual_type)) { | 11125 | if (!type_has_bits(actual_type)) { |
| ... | @@ -11282,8 +11365,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { | ... | @@ -11282,8 +11365,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 11282 | return nullptr; | 11365 | return nullptr; |
| 11283 | | 11366 | |
| 11284 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 11367 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 11285 | true, false, PtrLenUnknown, | 11368 | true, false, PtrLenUnknown, 0, 0, 0); |
| 11286 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); | | |
| 11287 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); | 11369 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 11288 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); | 11370 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 11289 | if (type_is_invalid(casted_value->value.type)) | 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,8 +11655,6 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11573 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); | 11655 | ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); |
| 11574 | if (type_is_invalid(resolved_type)) | 11656 | if (type_is_invalid(resolved_type)) |
| 11575 | return resolved_type; | 11657 | return resolved_type; |
| 11576 | if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type))) | | |
| 11577 | return resolved_type; | | |
| 11578 | | 11658 | |
| 11579 | bool operator_allowed; | 11659 | bool operator_allowed; |
| 11580 | switch (resolved_type->id) { | 11660 | switch (resolved_type->id) { |
| ... | @@ -11630,6 +11710,9 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op | ... | @@ -11630,6 +11710,9 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op |
| 11630 | if (casted_op2 == ira->codegen->invalid_instruction) | 11710 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 11631 | return ira->codegen->builtin_types.entry_invalid; | 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 | bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type); | 11716 | bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type); |
| 11634 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { | 11717 | if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) { |
| 11635 | ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); | 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,7 +12399,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12316 | out_array_val = out_val; | 12399 | out_array_val = out_val; |
| 12317 | } else if (is_slice(op1_type) || is_slice(op2_type)) { | 12400 | } else if (is_slice(op1_type) || is_slice(op2_type)) { |
| 12318 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, | 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 | result_type = get_slice_type(ira->codegen, ptr_type); | 12403 | result_type = get_slice_type(ira->codegen, ptr_type); |
| 12321 | out_array_val = create_const_vals(1); | 12404 | out_array_val = create_const_vals(1); |
| 12322 | out_array_val->special = ConstValSpecialStatic; | 12405 | out_array_val->special = ConstValSpecialStatic; |
| ... | @@ -12337,8 +12420,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc | ... | @@ -12337,8 +12420,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc |
| 12337 | new_len += 1; // null byte | 12420 | new_len += 1; // null byte |
| 12338 | | 12421 | |
| 12339 | // TODO make this `[*]null T` instead of `[*]T` | 12422 | // TODO make this `[*]null T` instead of `[*]T` |
| 12340 | result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, | 12423 | result_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, 0, 0, 0); |
| 12341 | PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); | | |
| 12342 | | 12424 | |
| 12343 | out_array_val = create_const_vals(1); | 12425 | out_array_val = create_const_vals(1); |
| 12344 | out_array_val->special = ConstValSpecialStatic; | 12426 | out_array_val->special = ConstValSpecialStatic; |
| ... | @@ -12563,7 +12645,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec | ... | @@ -12563,7 +12645,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec |
| 12563 | if (type_is_invalid(result_type)) { | 12645 | if (type_is_invalid(result_type)) { |
| 12564 | result_type = ira->codegen->builtin_types.entry_invalid; | 12646 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 12565 | } else { | 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 | result_type = ira->codegen->builtin_types.entry_invalid; | 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,6 +12713,11 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec |
| 12631 | } | 12713 | } |
| 12632 | | 12714 | |
| 12633 | if (decl_var_instruction->align_value == nullptr) { | 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 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); | 12721 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); |
| 12635 | } else { | 12722 | } else { |
| 12636 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->other, &var->align_bytes)) { | 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,7 +13187,6 @@ static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { |
| 13100 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, | 13187 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13101 | ZigVar *var) | 13188 | ZigVar *var) |
| 13102 | { | 13189 | { |
| 13103 | Error err; | | |
| 13104 | while (var->next_var != nullptr) { | 13190 | while (var->next_var != nullptr) { |
| 13105 | var = var->next_var; | 13191 | var = var->next_var; |
| 13106 | } | 13192 | } |
| ... | @@ -13158,8 +13244,6 @@ no_mem_slot: | ... | @@ -13158,8 +13244,6 @@ no_mem_slot: |
| 13158 | instruction->scope, instruction->source_node, var); | 13244 | instruction->scope, instruction->source_node, var); |
| 13159 | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type, | 13245 | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type, |
| 13160 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0); | 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 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); | 13248 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 13165 | var_ptr_instruction->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; | 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,8 +13440,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13356 | IrInstruction *casted_new_stack = nullptr; | 13440 | IrInstruction *casted_new_stack = nullptr; |
| 13357 | if (call_instruction->new_stack != nullptr) { | 13441 | if (call_instruction->new_stack != nullptr) { |
| 13358 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 13442 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 13359 | false, false, PtrLenUnknown, | 13443 | false, false, PtrLenUnknown, 0, 0, 0); |
| 13360 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); | | |
| 13361 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); | 13444 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 13362 | IrInstruction *new_stack = call_instruction->new_stack->other; | 13445 | IrInstruction *new_stack = call_instruction->new_stack->other; |
| 13363 | if (type_is_invalid(new_stack->value.type)) | 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,7 +13619,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr |
| 13536 | inst_fn_type_id.return_type = specified_return_type; | 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 | return ira->codegen->builtin_types.entry_invalid; | 13623 | return ira->codegen->builtin_types.entry_invalid; |
| 13541 | | 13624 | |
| 13542 | if (type_requires_comptime(specified_return_type)) { | 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,7 +14295,7 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 14212 | ptr_type->data.pointer.child_type, | 14295 | ptr_type->data.pointer.child_type, |
| 14213 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 14296 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 14214 | ptr_len, | 14297 | ptr_len, |
| 14215 | ptr_type->data.pointer.alignment, | 14298 | ptr_type->data.pointer.explicit_alignment, |
| 14216 | ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); | 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,7 +14347,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14264 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, | 14347 | return_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 14265 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 14348 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 14266 | elem_ptr_instruction->ptr_len, | 14349 | elem_ptr_instruction->ptr_len, |
| 14267 | ptr_type->data.pointer.alignment, 0, 0); | 14350 | ptr_type->data.pointer.explicit_alignment, 0, 0); |
| 14268 | } else { | 14351 | } else { |
| 14269 | uint64_t elem_val_scalar; | 14352 | uint64_t elem_val_scalar; |
| 14270 | if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar)) | 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,7 +14419,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle |
| 14336 | | 14419 | |
| 14337 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); | 14420 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 14338 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); | 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 | if (instr_is_comptime(casted_elem_index)) { | 14423 | if (instr_is_comptime(casted_elem_index)) { |
| 14341 | uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint); | 14424 | uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint); |
| 14342 | if (array_type->id == ZigTypeIdArray) { | 14425 | if (array_type->id == ZigTypeIdArray) { |
| ... | @@ -14653,9 +14736,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -14653,9 +14736,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14653 | } | 14736 | } |
| 14654 | | 14737 | |
| 14655 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, | 14738 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 14656 | is_const, is_volatile, | 14739 | is_const, is_volatile, PtrLenSingle, 0, 0, 0); |
| 14657 | PtrLenSingle, | | |
| 14658 | get_abi_alignment(ira->codegen, field_type), 0, 0); | | |
| 14659 | | 14740 | |
| 14660 | IrInstruction *result = ir_get_const(ira, source_instr); | 14741 | IrInstruction *result = ir_get_const(ira, source_instr); |
| 14661 | ConstExprValue *const_val = &result->value; | 14742 | ConstExprValue *const_val = &result->value; |
| ... | @@ -14669,7 +14750,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ | ... | @@ -14669,7 +14750,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14669 | | 14750 | |
| 14670 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field); | 14751 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, container_ptr, field); |
| 14671 | result->value.type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, | 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 | return result; | 14754 | return result; |
| 14674 | } else { | 14755 | } else { |
| 14675 | return ir_analyze_container_member_access_inner(ira, bare_type, field_name, | 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,9 +15083,14 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi |
| 15002 | } else if (buf_eql_str(field_name, "alignment")) { | 15083 | } else if (buf_eql_str(field_name, "alignment")) { |
| 15003 | bool ptr_is_const = true; | 15084 | bool ptr_is_const = true; |
| 15004 | bool ptr_is_volatile = false; | 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 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, | 15091 | return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, |
| 15006 | create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int, | 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 | ira->codegen->builtin_types.entry_num_lit_int, | 15094 | ira->codegen->builtin_types.entry_num_lit_int, |
| 15009 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); | 15095 | ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); |
| 15010 | } else { | 15096 | } else { |
| ... | @@ -15461,7 +15547,7 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -15461,7 +15547,7 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15461 | IrInstructionSliceType *slice_type_instruction) | 15547 | IrInstructionSliceType *slice_type_instruction) |
| 15462 | { | 15548 | { |
| 15463 | Error err; | 15549 | Error err; |
| 15464 | uint32_t align_bytes; | 15550 | uint32_t align_bytes = 0; |
| 15465 | if (slice_type_instruction->align_value != nullptr) { | 15551 | if (slice_type_instruction->align_value != nullptr) { |
| 15466 | if (!ir_resolve_align(ira, slice_type_instruction->align_value->other, &align_bytes)) | 15552 | if (!ir_resolve_align(ira, slice_type_instruction->align_value->other, &align_bytes)) |
| 15467 | return ira->codegen->builtin_types.entry_invalid; | 15553 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -15471,12 +15557,6 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, | ... | @@ -15471,12 +15557,6 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15471 | if (type_is_invalid(child_type)) | 15557 | if (type_is_invalid(child_type)) |
| 15472 | return ira->codegen->builtin_types.entry_invalid; | 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 | bool is_const = slice_type_instruction->is_const; | 15560 | bool is_const = slice_type_instruction->is_const; |
| 15481 | bool is_volatile = slice_type_instruction->is_volatile; | 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,7 +15591,7 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 15511 | case ZigTypeIdBoundFn: | 15591 | case ZigTypeIdBoundFn: |
| 15512 | case ZigTypeIdPromise: | 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 | return ira->codegen->builtin_types.entry_invalid; | 15595 | return ira->codegen->builtin_types.entry_invalid; |
| 15516 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, | 15596 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 15517 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); | 15597 | is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); |
| ... | @@ -15751,9 +15831,7 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, | ... | @@ -15751,9 +15831,7 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, |
| 15751 | } | 15831 | } |
| 15752 | ZigType *child_type = type_entry->data.maybe.child_type; | 15832 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 15753 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, | 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, | 15834 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, 0, 0, 0); |
| 15755 | PtrLenSingle, | | |
| 15756 | get_abi_alignment(ira->codegen, child_type), 0, 0); | | |
| 15757 | | 15835 | |
| 15758 | if (instr_is_comptime(value)) { | 15836 | if (instr_is_comptime(value)) { |
| 15759 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 15837 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| ... | @@ -16123,7 +16201,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, | ... | @@ -16123,7 +16201,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 16123 | return tag_type; | 16201 | return tag_type; |
| 16124 | } | 16202 | } |
| 16125 | case ZigTypeIdEnum: { | 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 | return ira->codegen->builtin_types.entry_invalid; | 16205 | return ira->codegen->builtin_types.entry_invalid; |
| 16128 | if (target_type->data.enumeration.src_field_count < 2) { | 16206 | if (target_type->data.enumeration.src_field_count < 2) { |
| 16129 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; | 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,7 +16430,7 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc |
| 16352 | if (casted_field_value == ira->codegen->invalid_instruction) | 16430 | if (casted_field_value == ira->codegen->invalid_instruction) |
| 16353 | return ira->codegen->builtin_types.entry_invalid; | 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 | return ira->codegen->builtin_types.entry_invalid; | 16434 | return ira->codegen->builtin_types.entry_invalid; |
| 16357 | | 16435 | |
| 16358 | bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope); | 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,7 +16830,7 @@ static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErr |
| 16752 | return ira->codegen->builtin_types.entry_invalid; | 16830 | return ira->codegen->builtin_types.entry_invalid; |
| 16753 | | 16831 | |
| 16754 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 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 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); | 16834 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16757 | if (casted_value->value.special == ConstValSpecialStatic) { | 16835 | if (casted_value->value.special == ConstValSpecialStatic) { |
| 16758 | ErrorTableEntry *err = casted_value->value.data.x_err_set; | 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,7 +16857,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi |
| 16779 | assert(target->value.type->id == ZigTypeIdEnum); | 16857 | assert(target->value.type->id == ZigTypeIdEnum); |
| 16780 | | 16858 | |
| 16781 | if (instr_is_comptime(target)) { | 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 | return ira->codegen->builtin_types.entry_invalid; | 16861 | return ira->codegen->builtin_types.entry_invalid; |
| 16784 | TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); | 16862 | TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); |
| 16785 | ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name); | 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,8 +16872,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi |
| 16794 | ZigType *u8_ptr_type = get_pointer_to_type_extra( | 16872 | ZigType *u8_ptr_type = get_pointer_to_type_extra( |
| 16795 | ira->codegen, ira->codegen->builtin_types.entry_u8, | 16873 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 16796 | true, false, PtrLenUnknown, | 16874 | true, false, PtrLenUnknown, |
| 16797 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), | 16875 | 0, 0, 0); |
| 16798 | 0, 0); | | |
| 16799 | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); | 16876 | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); |
| 16800 | return result->value.type; | 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,8 +17235,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco |
| 17158 | ZigType *u8_ptr = get_pointer_to_type_extra( | 17235 | ZigType *u8_ptr = get_pointer_to_type_extra( |
| 17159 | ira->codegen, ira->codegen->builtin_types.entry_u8, | 17236 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 17160 | true, false, PtrLenUnknown, | 17237 | true, false, PtrLenUnknown, |
| 17161 | get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), | 17238 | 0, 0, 0); |
| 17162 | 0, 0); | | |
| 17163 | fn_def_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); | 17239 | fn_def_fields[6].type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); |
| 17164 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { | 17240 | if (fn_node->is_extern && buf_len(fn_node->lib_name) > 0) { |
| 17165 | fn_def_fields[6].data.x_optional = create_const_vals(1); | 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,7 +17355,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 17279 | ensure_field_index(result->type, "alignment", 3); | 17355 | ensure_field_index(result->type, "alignment", 3); |
| 17280 | fields[3].special = ConstValSpecialStatic; | 17356 | fields[3].special = ConstValSpecialStatic; |
| 17281 | fields[3].type = get_int_type(ira->codegen, false, 29); | 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 | // child: type | 17359 | // child: type |
| 17284 | ensure_field_index(result->type, "child", 4); | 17360 | ensure_field_index(result->type, "child", 4); |
| 17285 | fields[4].special = ConstValSpecialStatic; | 17361 | fields[4].special = ConstValSpecialStatic; |
| ... | @@ -18369,7 +18445,21 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio | ... | @@ -18369,7 +18445,21 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio |
| 18369 | return dest_type; | 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 | static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { | 18460 | static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { |
| | 18461 | Error err; |
| | 18462 | |
| 18373 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); | 18463 | ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); |
| 18374 | if (type_is_invalid(dest_child_type)) | 18464 | if (type_is_invalid(dest_child_type)) |
| 18375 | return ira->codegen->builtin_types.entry_invalid; | 18465 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18384,15 +18474,23 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF | ... | @@ -18384,15 +18474,23 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18384 | if (target->value.type->id == ZigTypeIdPointer) { | 18474 | if (target->value.type->id == ZigTypeIdPointer) { |
| 18385 | src_ptr_const = target->value.type->data.pointer.is_const; | 18475 | src_ptr_const = target->value.type->data.pointer.is_const; |
| 18386 | src_ptr_volatile = target->value.type->data.pointer.is_volatile; | 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 | } else if (is_slice(target->value.type)) { | 18480 | } else if (is_slice(target->value.type)) { |
| 18389 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 18481 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; |
| 18390 | src_ptr_const = src_ptr_type->data.pointer.is_const; | 18482 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 18391 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; | 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 | } else { | 18487 | } else { |
| 18394 | src_ptr_const = true; | 18488 | src_ptr_const = true; |
| 18395 | src_ptr_volatile = false; | 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 | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); | 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,6 +18548,8 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF |
| 18450 | } | 18548 | } |
| 18451 | | 18549 | |
| 18452 | static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { | 18550 | static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { |
| | 18551 | Error err; |
| | 18552 | |
| 18453 | IrInstruction *target = instruction->target->other; | 18553 | IrInstruction *target = instruction->target->other; |
| 18454 | if (type_is_invalid(target->value.type)) | 18554 | if (type_is_invalid(target->value.type)) |
| 18455 | return ira->codegen->builtin_types.entry_invalid; | 18555 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18462,9 +18562,13 @@ static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToB | ... | @@ -18462,9 +18562,13 @@ static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToB |
| 18462 | | 18562 | |
| 18463 | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; | 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 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 18569 | ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 18466 | src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, | 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 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); | 18572 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 18469 | | 18573 | |
| 18470 | IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); | 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,6 +18726,8 @@ static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoo |
| 18622 | } | 18726 | } |
| 18623 | | 18727 | |
| 18624 | static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { | 18728 | static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { |
| | 18729 | Error err; |
| | 18730 | |
| 18625 | IrInstruction *dest_ptr = instruction->dest_ptr->other; | 18731 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18626 | if (type_is_invalid(dest_ptr->value.type)) | 18732 | if (type_is_invalid(dest_ptr->value.type)) |
| 18627 | return ira->codegen->builtin_types.entry_invalid; | 18733 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18640,8 +18746,13 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse | ... | @@ -18640,8 +18746,13 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18640 | | 18746 | |
| 18641 | ZigType *usize = ira->codegen->builtin_types.entry_usize; | 18747 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18642 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; | 18748 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 18643 | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? | 18749 | uint32_t dest_align; |
| 18644 | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); | 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 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, | 18756 | ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, |
| 18646 | PtrLenUnknown, dest_align, 0, 0); | 18757 | PtrLenUnknown, dest_align, 0, 0); |
| 18647 | | 18758 | |
| ... | @@ -18714,6 +18825,8 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse | ... | @@ -18714,6 +18825,8 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse |
| 18714 | } | 18825 | } |
| 18715 | | 18826 | |
| 18716 | static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { | 18827 | static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { |
| | 18828 | Error err; |
| | 18829 | |
| 18717 | IrInstruction *dest_ptr = instruction->dest_ptr->other; | 18830 | IrInstruction *dest_ptr = instruction->dest_ptr->other; |
| 18718 | if (type_is_invalid(dest_ptr->value.type)) | 18831 | if (type_is_invalid(dest_ptr->value.type)) |
| 18719 | return ira->codegen->builtin_types.entry_invalid; | 18832 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -18733,10 +18846,22 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp | ... | @@ -18733,10 +18846,22 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp |
| 18733 | dest_uncasted_type->data.pointer.is_volatile; | 18846 | dest_uncasted_type->data.pointer.is_volatile; |
| 18734 | bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && | 18847 | bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && |
| 18735 | src_uncasted_type->data.pointer.is_volatile; | 18848 | src_uncasted_type->data.pointer.is_volatile; |
| 18736 | uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? | 18849 | |
| 18737 | dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); | 18850 | uint32_t dest_align; |
| 18738 | uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ? | 18851 | if (dest_uncasted_type->id == ZigTypeIdPointer) { |
| 18739 | src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); | 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 | ZigType *usize = ira->codegen->builtin_types.entry_usize; | 18866 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 18742 | ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, | 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,17 +19006,13 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 18881 | ZigType *return_type; | 19006 | ZigType *return_type; |
| 18882 | | 19007 | |
| 18883 | if (array_type->id == ZigTypeIdArray) { | 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 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && | 19009 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 18889 | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; | 19010 | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 18890 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, | 19011 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, |
| 18891 | ptr_type->data.pointer.is_const || is_comptime_const, | 19012 | ptr_type->data.pointer.is_const || is_comptime_const, |
| 18892 | ptr_type->data.pointer.is_volatile, | 19013 | ptr_type->data.pointer.is_volatile, |
| 18893 | PtrLenUnknown, | 19014 | PtrLenUnknown, |
| 18894 | byte_alignment, 0, 0); | 19015 | ptr_type->data.pointer.explicit_alignment, 0, 0); |
| 18895 | return_type = get_slice_type(ira->codegen, slice_ptr_type); | 19016 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18896 | } else if (array_type->id == ZigTypeIdPointer) { | 19017 | } else if (array_type->id == ZigTypeIdPointer) { |
| 18897 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { | 19018 | if (array_type->data.pointer.ptr_len == PtrLenSingle) { |
| ... | @@ -18901,7 +19022,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice | ... | @@ -18901,7 +19022,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 18901 | main_type->data.pointer.child_type, | 19022 | main_type->data.pointer.child_type, |
| 18902 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, | 19023 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18903 | PtrLenUnknown, | 19024 | PtrLenUnknown, |
| 18904 | array_type->data.pointer.alignment, 0, 0); | 19025 | array_type->data.pointer.explicit_alignment, 0, 0); |
| 18905 | return_type = get_slice_type(ira->codegen, slice_ptr_type); | 19026 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18906 | } else { | 19027 | } else { |
| 18907 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer")); | 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,7 +19032,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice |
| 18911 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, | 19032 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, |
| 18912 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, | 19033 | array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, |
| 18913 | PtrLenUnknown, | 19034 | PtrLenUnknown, |
| 18914 | array_type->data.pointer.alignment, 0, 0); | 19035 | array_type->data.pointer.explicit_alignment, 0, 0); |
| 18915 | return_type = get_slice_type(ira->codegen, slice_ptr_type); | 19036 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 18916 | if (!end) { | 19037 | if (!end) { |
| 18917 | ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value")); | 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,7 +19413,7 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli |
| 19292 | return ira->codegen->builtin_types.entry_invalid; | 19413 | return ira->codegen->builtin_types.entry_invalid; |
| 19293 | ZigType *type_entry = ir_resolve_type(ira, type_value); | 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 | return ira->codegen->builtin_types.entry_invalid; | 19417 | return ira->codegen->builtin_types.entry_invalid; |
| 19297 | | 19418 | |
| 19298 | switch (type_entry->id) { | 19419 | switch (type_entry->id) { |
| ... | @@ -19336,6 +19457,8 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli | ... | @@ -19336,6 +19457,8 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli |
| 19336 | } | 19457 | } |
| 19337 | | 19458 | |
| 19338 | static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { | 19459 | static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { |
| | 19460 | Error err; |
| | 19461 | |
| 19339 | IrInstruction *type_value = instruction->type_value->other; | 19462 | IrInstruction *type_value = instruction->type_value->other; |
| 19340 | if (type_is_invalid(type_value->value.type)) | 19463 | if (type_is_invalid(type_value->value.type)) |
| 19341 | return ira->codegen->builtin_types.entry_invalid; | 19464 | return ira->codegen->builtin_types.entry_invalid; |
| ... | @@ -19379,10 +19502,13 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction | ... | @@ -19379,10 +19502,13 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction |
| 19379 | | 19502 | |
| 19380 | ZigType *expected_ptr_type; | 19503 | ZigType *expected_ptr_type; |
| 19381 | if (result_ptr->value.type->id == ZigTypeIdPointer) { | 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 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, | 19508 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 19383 | false, result_ptr->value.type->data.pointer.is_volatile, | 19509 | false, result_ptr->value.type->data.pointer.is_volatile, |
| 19384 | PtrLenSingle, | 19510 | PtrLenSingle, |
| 19385 | result_ptr->value.type->data.pointer.alignment, 0, 0); | 19511 | alignment, 0, 0); |
| 19386 | } else { | 19512 | } else { |
| 19387 | expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false); | 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,8 +19670,7 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19544 | } | 19670 | } |
| 19545 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, | 19671 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, |
| 19546 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, | 19672 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 19547 | PtrLenSingle, | 19673 | PtrLenSingle, 0, 0, 0); |
| 19548 | get_abi_alignment(ira->codegen, payload_type), 0, 0); | | |
| 19549 | if (instr_is_comptime(value)) { | 19674 | if (instr_is_comptime(value)) { |
| 19550 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); | 19675 | ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); |
| 19551 | if (!ptr_val) | 19676 | if (!ptr_val) |
| ... | @@ -19624,7 +19749,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP | ... | @@ -19624,7 +19749,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP |
| 19624 | ZigType *param_type = ir_resolve_type(ira, param_type_value); | 19749 | ZigType *param_type = ir_resolve_type(ira, param_type_value); |
| 19625 | if (type_is_invalid(param_type)) | 19750 | if (type_is_invalid(param_type)) |
| 19626 | return ira->codegen->builtin_types.entry_invalid; | 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 | return ira->codegen->builtin_types.entry_invalid; | 19753 | return ira->codegen->builtin_types.entry_invalid; |
| 19629 | if (type_requires_comptime(param_type)) { | 19754 | if (type_requires_comptime(param_type)) { |
| 19630 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { | 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,7 +20024,7 @@ static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic |
| 19899 | } | 20024 | } |
| 19900 | | 20025 | |
| 19901 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, | 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 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); | 20028 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 19904 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); | 20029 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 19905 | if (type_is_invalid(casted_msg->value.type)) | 20030 | if (type_is_invalid(casted_msg->value.type)) |
| ... | @@ -19912,6 +20037,8 @@ static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic | ... | @@ -19912,6 +20037,8 @@ static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic |
| 19912 | } | 20037 | } |
| 19913 | | 20038 | |
| 19914 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { | 20039 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| | 20040 | Error err; |
| | 20041 | |
| 19915 | ZigType *target_type = target->value.type; | 20042 | ZigType *target_type = target->value.type; |
| 19916 | assert(!type_is_invalid(target_type)); | 20043 | assert(!type_is_invalid(target_type)); |
| 19917 | | 20044 | |
| ... | @@ -19920,7 +20047,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 | ... | @@ -19920,7 +20047,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19920 | | 20047 | |
| 19921 | if (target_type->id == ZigTypeIdPointer) { | 20048 | if (target_type->id == ZigTypeIdPointer) { |
| 19922 | result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); | 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 | } else if (target_type->id == ZigTypeIdFn) { | 20052 | } else if (target_type->id == ZigTypeIdFn) { |
| 19925 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; | 20053 | FnTypeId fn_type_id = target_type->data.fn.fn_type_id; |
| 19926 | old_align_bytes = fn_type_id.alignment; | 20054 | old_align_bytes = fn_type_id.alignment; |
| ... | @@ -19930,7 +20058,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 | ... | @@ -19930,7 +20058,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19930 | target_type->data.maybe.child_type->id == ZigTypeIdPointer) | 20058 | target_type->data.maybe.child_type->id == ZigTypeIdPointer) |
| 19931 | { | 20059 | { |
| 19932 | ZigType *ptr_type = target_type->data.maybe.child_type; | 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 | ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); | 20063 | ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); |
| 19935 | | 20064 | |
| 19936 | result_type = get_optional_type(ira->codegen, better_ptr_type); | 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,7 +20073,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 19944 | result_type = get_optional_type(ira->codegen, fn_type); | 20073 | result_type = get_optional_type(ira->codegen, fn_type); |
| 19945 | } else if (is_slice(target_type)) { | 20074 | } else if (is_slice(target_type)) { |
| 19946 | ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; | 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 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); | 20078 | ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); |
| 19949 | result_type = get_slice_type(ira->codegen, result_ptr_type); | 20079 | result_type = get_slice_type(ira->codegen, result_ptr_type); |
| 19950 | } else { | 20080 | } else { |
| ... | @@ -20023,8 +20153,13 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr | ... | @@ -20023,8 +20153,13 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr |
| 20023 | return dest_type; | 20153 | return dest_type; |
| 20024 | } | 20154 | } |
| 20025 | | 20155 | |
| 20026 | uint32_t src_align_bytes = get_ptr_align(ira->codegen, src_type); | 20156 | uint32_t src_align_bytes; |
| 20027 | uint32_t dest_align_bytes = get_ptr_align(ira->codegen, dest_type); | 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 | if (dest_align_bytes > src_align_bytes) { | 20164 | if (dest_align_bytes > src_align_bytes) { |
| 20030 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cast increases pointer alignment")); | 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,7 +20176,7 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr |
| 20041 | | 20176 | |
| 20042 | // Keep the bigger alignment, it can only help- | 20177 | // Keep the bigger alignment, it can only help- |
| 20043 | // unless the target is zero bits. | 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 | return ira->codegen->builtin_types.entry_invalid; | 20180 | return ira->codegen->builtin_types.entry_invalid; |
| 20046 | | 20181 | |
| 20047 | IrInstruction *result; | 20182 | IrInstruction *result; |
| ... | @@ -20289,7 +20424,7 @@ static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionI | ... | @@ -20289,7 +20424,7 @@ static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionI |
| 20289 | return ira->codegen->builtin_types.entry_invalid; | 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 | return ira->codegen->builtin_types.entry_invalid; | 20428 | return ira->codegen->builtin_types.entry_invalid; |
| 20294 | if (!type_has_bits(dest_type)) { | 20429 | if (!type_has_bits(dest_type)) { |
| 20295 | ir_add_error(ira, dest_type_value, | 20430 | ir_add_error(ira, dest_type_value, |
| ... | @@ -20440,12 +20575,15 @@ static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtr | ... | @@ -20440,12 +20575,15 @@ static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtr |
| 20440 | if (instruction->align_value != nullptr) { | 20575 | if (instruction->align_value != nullptr) { |
| 20441 | if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes)) | 20576 | if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes)) |
| 20442 | return ira->codegen->builtin_types.entry_invalid; | 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 | } else { | 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 | return ira->codegen->builtin_types.entry_invalid; | 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 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); | 20587 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 20450 | out_val->data.x_type = get_pointer_to_type_extra(ira->codegen, child_type, | 20588 | out_val->data.x_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 20451 | instruction->is_const, instruction->is_volatile, | 20589 | instruction->is_const, instruction->is_volatile, |
| ... | @@ -21089,7 +21227,7 @@ static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstruction | ... | @@ -21089,7 +21227,7 @@ static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstruction |
| 21089 | return ira->codegen->builtin_types.entry_invalid; | 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 | return ira->codegen->builtin_types.entry_invalid; | 21231 | return ira->codegen->builtin_types.entry_invalid; |
| 21094 | | 21232 | |
| 21095 | ZigType *tag_type = target->value.type->data.enumeration.tag_int_type; | 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,7 +21250,7 @@ static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstruction |
| 21112 | return ira->codegen->builtin_types.entry_invalid; | 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 | return ira->codegen->builtin_types.entry_invalid; | 21254 | return ira->codegen->builtin_types.entry_invalid; |
| 21117 | | 21255 | |
| 21118 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; | 21256 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |