| ... | ... | @@ -16899,12 +16899,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 16899 | 16899 | return ira->codegen->invalid_instruction; |
| 16900 | 16900 | |
| 16901 | 16901 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 16902 | | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 16903 | | return ira->codegen->invalid_instruction; |
| 16904 | | |
| 16905 | | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 16906 | | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| 16907 | | uint64_t ptr_align = get_ptr_align(ira->codegen, return_type); |
| 16908 | 16902 | if (instr_is_comptime(casted_elem_index)) { |
| 16909 | 16903 | uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint); |
| 16910 | 16904 | if (array_type->id == ZigTypeIdArray) { |
| ... | ... | @@ -16918,8 +16912,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 16918 | 16912 | safety_check_on = false; |
| 16919 | 16913 | } |
| 16920 | 16914 | |
| 16921 | | { |
| 16915 | if (return_type->data.pointer.explicit_alignment != 0) { |
| 16922 | 16916 | // figure out the largest alignment possible |
| 16917 | |
| 16918 | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 16919 | return ira->codegen->invalid_instruction; |
| 16920 | |
| 16921 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 16922 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| 16923 | uint64_t ptr_align = get_ptr_align(ira->codegen, return_type); |
| 16924 | |
| 16923 | 16925 | uint64_t chosen_align = abi_align; |
| 16924 | 16926 | if (ptr_align >= abi_align) { |
| 16925 | 16927 | while (ptr_align > abi_align) { |
| ... | ... | @@ -17148,15 +17150,24 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 17148 | 17150 | case ReqCompTimeNo: |
| 17149 | 17151 | break; |
| 17150 | 17152 | } |
| 17151 | | if (ptr_align < abi_align) { |
| 17152 | | if (elem_size >= ptr_align && elem_size % ptr_align == 0) { |
| 17153 | | return_type = adjust_ptr_align(ira->codegen, return_type, ptr_align); |
| 17153 | |
| 17154 | if (return_type->data.pointer.explicit_alignment != 0) { |
| 17155 | if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown))) |
| 17156 | return ira->codegen->invalid_instruction; |
| 17157 | |
| 17158 | uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type); |
| 17159 | uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type); |
| 17160 | uint64_t ptr_align = get_ptr_align(ira->codegen, return_type); |
| 17161 | if (ptr_align < abi_align) { |
| 17162 | if (elem_size >= ptr_align && elem_size % ptr_align == 0) { |
| 17163 | return_type = adjust_ptr_align(ira->codegen, return_type, ptr_align); |
| 17164 | } else { |
| 17165 | // can't get here because guaranteed elem_size >= abi_align |
| 17166 | zig_unreachable(); |
| 17167 | } |
| 17154 | 17168 | } else { |
| 17155 | | // can't get here because guaranteed elem_size >= abi_align |
| 17156 | | zig_unreachable(); |
| 17169 | return_type = adjust_ptr_align(ira->codegen, return_type, abi_align); |
| 17157 | 17170 | } |
| 17158 | | } else { |
| 17159 | | return_type = adjust_ptr_align(ira->codegen, return_type, abi_align); |
| 17160 | 17171 | } |
| 17161 | 17172 | } |
| 17162 | 17173 | |