| ... | ... | @@ -12613,10 +12613,27 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 12613 | 12613 | return true; |
| 12614 | 12614 | } |
| 12615 | 12615 | |
| 12616 | | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out) { |
| 12616 | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) { |
| 12617 | 12617 | if (type_is_invalid(value->value.type)) |
| 12618 | 12618 | return false; |
| 12619 | 12619 | |
| 12620 | // Look for this pattern: `*align(@alignOf(T)) T`. |
| 12621 | // This can be resolved to be `*out = 0` without resolving any alignment. |
| 12622 | if (elem_type != nullptr && value->value.special == ConstValSpecialLazy && |
| 12623 | value->value.data.x_lazy->id == LazyValueIdAlignOf) |
| 12624 | { |
| 12625 | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value.data.x_lazy); |
| 12626 | |
| 12627 | ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type); |
| 12628 | if (type_is_invalid(lazy_elem_type)) |
| 12629 | return false; |
| 12630 | |
| 12631 | if (elem_type == lazy_elem_type) { |
| 12632 | *out = 0; |
| 12633 | return true; |
| 12634 | } |
| 12635 | } |
| 12636 | |
| 12620 | 12637 | IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 12621 | 12638 | if (type_is_invalid(casted_value->value.type)) |
| 12622 | 12639 | return false; |
| ... | ... | @@ -14424,7 +14441,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 14424 | 14441 | } |
| 14425 | 14442 | var->align_bytes = get_abi_alignment(ira->codegen, result_type); |
| 14426 | 14443 | } else { |
| 14427 | | if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, &var->align_bytes)) { |
| 14444 | if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) { |
| 14428 | 14445 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 14429 | 14446 | } |
| 14430 | 14447 | } |
| ... | ... | @@ -14879,7 +14896,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 14879 | 14896 | |
| 14880 | 14897 | if (alloca_src->base.child == nullptr || is_comptime) { |
| 14881 | 14898 | uint32_t align = 0; |
| 14882 | | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, &align)) { |
| 14899 | if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) { |
| 14883 | 14900 | return ira->codegen->invalid_instruction; |
| 14884 | 14901 | } |
| 14885 | 14902 | IrInstruction *alloca_gen; |
| ... | ... | @@ -15896,7 +15913,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 15896 | 15913 | copy_const_val(&const_instruction->base.value, align_result, true); |
| 15897 | 15914 | |
| 15898 | 15915 | uint32_t align_bytes = 0; |
| 15899 | | ir_resolve_align(ira, &const_instruction->base, &align_bytes); |
| 15916 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| 15900 | 15917 | impl_fn->align_bytes = align_bytes; |
| 15901 | 15918 | inst_fn_type_id.alignment = align_bytes; |
| 15902 | 15919 | } |
| ... | ... | @@ -23948,7 +23965,7 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 23948 | 23965 | static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 23949 | 23966 | uint32_t align_bytes; |
| 23950 | 23967 | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 23951 | | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) |
| 23968 | if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes)) |
| 23952 | 23969 | return ira->codegen->invalid_instruction; |
| 23953 | 23970 | |
| 23954 | 23971 | IrInstruction *target = instruction->target->child; |
| ... | ... | @@ -23974,7 +23991,7 @@ static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstr |
| 23974 | 23991 | static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { |
| 23975 | 23992 | uint32_t align_bytes; |
| 23976 | 23993 | IrInstruction *align_bytes_inst = instruction->align_bytes->child; |
| 23977 | | if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) |
| 23994 | if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes)) |
| 23978 | 23995 | return ira->codegen->invalid_instruction; |
| 23979 | 23996 | |
| 23980 | 23997 | if (align_bytes > 256) { |
| ... | ... | @@ -25555,7 +25572,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 25555 | 25572 | } |
| 25556 | 25573 | |
| 25557 | 25574 | if (lazy_fn_type->align_inst != nullptr) { |
| 25558 | | if (!ir_resolve_align(ira, lazy_fn_type->align_inst, &fn_type_id.alignment)) |
| 25575 | if (!ir_resolve_align(ira, lazy_fn_type->align_inst, nullptr, &fn_type_id.alignment)) |
| 25559 | 25576 | return nullptr; |
| 25560 | 25577 | } |
| 25561 | 25578 | |
| ... | ... | @@ -25690,14 +25707,15 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 25690 | 25707 | LazyValueSliceType *lazy_slice_type = reinterpret_cast<LazyValueSliceType *>(val->data.x_lazy); |
| 25691 | 25708 | IrAnalyze *ira = lazy_slice_type->ira; |
| 25692 | 25709 | |
| 25710 | ZigType *elem_type = ir_resolve_type(ira, lazy_slice_type->elem_type); |
| 25711 | if (type_is_invalid(elem_type)) |
| 25712 | return ErrorSemanticAnalyzeFail; |
| 25713 | |
| 25693 | 25714 | uint32_t align_bytes = 0; |
| 25694 | 25715 | if (lazy_slice_type->align_inst != nullptr) { |
| 25695 | | if (!ir_resolve_align(ira, lazy_slice_type->align_inst, &align_bytes)) |
| 25716 | if (!ir_resolve_align(ira, lazy_slice_type->align_inst, elem_type, &align_bytes)) |
| 25696 | 25717 | return ErrorSemanticAnalyzeFail; |
| 25697 | 25718 | } |
| 25698 | | ZigType *elem_type = ir_resolve_type(ira, lazy_slice_type->elem_type); |
| 25699 | | if (type_is_invalid(elem_type)) |
| 25700 | | return ErrorSemanticAnalyzeFail; |
| 25701 | 25719 | |
| 25702 | 25720 | switch (elem_type->id) { |
| 25703 | 25721 | case ZigTypeIdInvalid: // handled above |
| ... | ... | @@ -25750,14 +25768,15 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 25750 | 25768 | LazyValuePtrType *lazy_ptr_type = reinterpret_cast<LazyValuePtrType *>(val->data.x_lazy); |
| 25751 | 25769 | IrAnalyze *ira = lazy_ptr_type->ira; |
| 25752 | 25770 | |
| 25771 | ZigType *elem_type = ir_resolve_type(ira, lazy_ptr_type->elem_type); |
| 25772 | if (type_is_invalid(elem_type)) |
| 25773 | return ErrorSemanticAnalyzeFail; |
| 25774 | |
| 25753 | 25775 | uint32_t align_bytes = 0; |
| 25754 | 25776 | if (lazy_ptr_type->align_inst != nullptr) { |
| 25755 | | if (!ir_resolve_align(ira, lazy_ptr_type->align_inst, &align_bytes)) |
| 25777 | if (!ir_resolve_align(ira, lazy_ptr_type->align_inst, elem_type, &align_bytes)) |
| 25756 | 25778 | return ErrorSemanticAnalyzeFail; |
| 25757 | 25779 | } |
| 25758 | | ZigType *elem_type = ir_resolve_type(ira, lazy_ptr_type->elem_type); |
| 25759 | | if (type_is_invalid(elem_type)) |
| 25760 | | return ErrorSemanticAnalyzeFail; |
| 25761 | 25780 | |
| 25762 | 25781 | if (elem_type->id == ZigTypeIdUnreachable) { |
| 25763 | 25782 | ir_add_error(ira, lazy_ptr_type->elem_type, |