| ... | ... | @@ -1630,7 +1630,9 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, |
| 1630 | 1630 | |
| 1631 | 1631 | bool big_endian = g->is_big_endian; |
| 1632 | 1632 | |
| 1633 | | LLVMValueRef containing_int = gen_load(g, ptr, ptr_type, ""); |
| 1633 | LLVMTypeRef int_ptr_ty = LLVMPointerType(LLVMIntType(host_int_bytes * 8), 0); |
| 1634 | LLVMValueRef int_ptr = LLVMBuildBitCast(g->builder, ptr, int_ptr_ty, ""); |
| 1635 | LLVMValueRef containing_int = gen_load(g, int_ptr, ptr_type, ""); |
| 1634 | 1636 | uint32_t host_bit_count = LLVMGetIntTypeWidth(LLVMTypeOf(containing_int)); |
| 1635 | 1637 | assert(host_bit_count == host_int_bytes * 8); |
| 1636 | 1638 | uint32_t size_in_bits = type_size_bits(g, child_type); |
| ... | ... | @@ -1654,7 +1656,7 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, |
| 1654 | 1656 | LLVMValueRef shifted_value = LLVMBuildShl(g->builder, extended_value, shift_amt_val, ""); |
| 1655 | 1657 | LLVMValueRef ored_value = LLVMBuildOr(g->builder, shifted_value, anded_containing_int, ""); |
| 1656 | 1658 | |
| 1657 | | gen_store(g, ored_value, ptr, ptr_type); |
| 1659 | gen_store(g, ored_value, int_ptr, ptr_type); |
| 1658 | 1660 | } |
| 1659 | 1661 | |
| 1660 | 1662 | static void gen_var_debug_decl(CodeGen *g, ZigVar *var) { |
| ... | ... | @@ -3375,7 +3377,10 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 3375 | 3377 | |
| 3376 | 3378 | bool big_endian = g->is_big_endian; |
| 3377 | 3379 | |
| 3378 | | LLVMValueRef containing_int = gen_load(g, ptr, ptr_type, ""); |
| 3380 | LLVMTypeRef int_ptr_ty = LLVMPointerType(LLVMIntType(host_int_bytes * 8), 0); |
| 3381 | LLVMValueRef int_ptr = LLVMBuildBitCast(g->builder, ptr, int_ptr_ty, ""); |
| 3382 | LLVMValueRef containing_int = gen_load(g, int_ptr, ptr_type, ""); |
| 3383 | |
| 3379 | 3384 | uint32_t host_bit_count = LLVMGetIntTypeWidth(LLVMTypeOf(containing_int)); |
| 3380 | 3385 | assert(host_bit_count == host_int_bytes * 8); |
| 3381 | 3386 | uint32_t size_in_bits = type_size_bits(g, child_type); |
| ... | ... | @@ -6693,8 +6698,10 @@ check: switch (const_val->special) { |
| 6693 | 6698 | make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(g, field_val->type, val); |
| 6694 | 6699 | } else { |
| 6695 | 6700 | bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type |
| 6696 | | LLVMTypeRef big_int_type_ref = LLVMStructGetTypeAtIndex(get_llvm_type(g, type_entry), |
| 6701 | LLVMTypeRef field_ty = LLVMStructGetTypeAtIndex(get_llvm_type(g, type_entry), |
| 6697 | 6702 | (unsigned)type_struct_field->gen_index); |
| 6703 | const size_t size_in_bytes = LLVMStoreSizeOfType(g->target_data_ref, field_ty); |
| 6704 | LLVMTypeRef big_int_type_ref = LLVMIntType(size_in_bytes * 8); |
| 6698 | 6705 | LLVMValueRef val = LLVMConstInt(big_int_type_ref, 0, false); |
| 6699 | 6706 | size_t used_bits = 0; |
| 6700 | 6707 | for (size_t i = src_field_index; i < src_field_index_end; i += 1) { |
| ... | ... | @@ -6717,7 +6724,22 @@ check: switch (const_val->special) { |
| 6717 | 6724 | used_bits += packed_bits_size; |
| 6718 | 6725 | } |
| 6719 | 6726 | } |
| 6720 | | fields[type_struct_field->gen_index] = val; |
| 6727 | if (LLVMGetTypeKind(field_ty) != LLVMArrayTypeKind) { |
| 6728 | assert(LLVMGetTypeKind(field_ty) == LLVMIntegerTypeKind); |
| 6729 | fields[type_struct_field->gen_index] = val; |
| 6730 | } else { |
| 6731 | const LLVMValueRef MASK = LLVMConstInt(LLVMInt8Type(), 255, false); |
| 6732 | const LLVMValueRef AMT = LLVMConstInt(LLVMInt8Type(), 8, false); |
| 6733 | |
| 6734 | LLVMValueRef *values = allocate<LLVMValueRef>(size_in_bytes); |
| 6735 | for (size_t i = 0; i < size_in_bytes; i++) { |
| 6736 | const size_t idx = is_big_endian ? size_in_bytes - 1 - i : i; |
| 6737 | values[idx] = LLVMConstTruncOrBitCast(LLVMConstAnd(val, MASK), LLVMInt8Type()); |
| 6738 | val = LLVMConstLShr(val, AMT); |
| 6739 | } |
| 6740 | |
| 6741 | fields[type_struct_field->gen_index] = LLVMConstArray(LLVMInt8Type(), values, size_in_bytes); |
| 6742 | } |
| 6721 | 6743 | } |
| 6722 | 6744 | |
| 6723 | 6745 | src_field_index = src_field_index_end; |