| ... | ... | @@ -1972,13 +1972,18 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty |
| 1972 | 1972 | uint32_t shift_amt = big_endian ? host_bit_count - bit_offset - size_in_bits : bit_offset; |
| 1973 | 1973 | LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false); |
| 1974 | 1974 | |
| 1975 | | LLVMValueRef mask_val = LLVMConstAllOnes(get_llvm_type(g, child_type)); |
| 1975 | // Convert to equally-sized integer type in order to perform the bit |
| 1976 | // operations on the value to store |
| 1977 | LLVMTypeRef value_bits_type = LLVMIntType(size_in_bits); |
| 1978 | LLVMValueRef value_bits = LLVMBuildBitCast(g->builder, value, value_bits_type, ""); |
| 1979 | |
| 1980 | LLVMValueRef mask_val = LLVMConstAllOnes(value_bits_type); |
| 1976 | 1981 | mask_val = LLVMConstZExt(mask_val, LLVMTypeOf(containing_int)); |
| 1977 | 1982 | mask_val = LLVMConstShl(mask_val, shift_amt_val); |
| 1978 | 1983 | mask_val = LLVMConstNot(mask_val); |
| 1979 | 1984 | |
| 1980 | 1985 | LLVMValueRef anded_containing_int = LLVMBuildAnd(g->builder, containing_int, mask_val, ""); |
| 1981 | | LLVMValueRef extended_value = LLVMBuildZExt(g->builder, value, LLVMTypeOf(containing_int), ""); |
| 1986 | LLVMValueRef extended_value = LLVMBuildZExt(g->builder, value_bits, LLVMTypeOf(containing_int), ""); |
| 1982 | 1987 | LLVMValueRef shifted_value = LLVMBuildShl(g->builder, extended_value, shift_amt_val, ""); |
| 1983 | 1988 | LLVMValueRef ored_value = LLVMBuildOr(g->builder, shifted_value, anded_containing_int, ""); |
| 1984 | 1989 | |
| ... | ... | @@ -3388,16 +3393,23 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrI |
| 3388 | 3393 | LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false); |
| 3389 | 3394 | LLVMValueRef shifted_value = LLVMBuildLShr(g->builder, containing_int, shift_amt_val, ""); |
| 3390 | 3395 | |
| 3391 | | if (!handle_is_ptr(child_type)) |
| 3392 | | return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), ""); |
| 3396 | if (handle_is_ptr(child_type)) { |
| 3397 | assert(instruction->tmp_ptr != nullptr); |
| 3398 | LLVMTypeRef same_size_int = LLVMIntType(size_in_bits); |
| 3399 | LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, ""); |
| 3400 | LLVMValueRef bitcasted_ptr = LLVMBuildBitCast(g->builder, instruction->tmp_ptr, |
| 3401 | LLVMPointerType(same_size_int, 0), ""); |
| 3402 | LLVMBuildStore(g->builder, truncated_int, bitcasted_ptr); |
| 3403 | return instruction->tmp_ptr; |
| 3404 | } |
| 3393 | 3405 | |
| 3394 | | assert(instruction->tmp_ptr != nullptr); |
| 3395 | | LLVMTypeRef same_size_int = LLVMIntType(size_in_bits); |
| 3396 | | LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, ""); |
| 3397 | | LLVMValueRef bitcasted_ptr = LLVMBuildBitCast(g->builder, instruction->tmp_ptr, |
| 3398 | | LLVMPointerType(same_size_int, 0), ""); |
| 3399 | | LLVMBuildStore(g->builder, truncated_int, bitcasted_ptr); |
| 3400 | | return instruction->tmp_ptr; |
| 3406 | if (child_type->id == ZigTypeIdFloat) { |
| 3407 | LLVMTypeRef same_size_int = LLVMIntType(size_in_bits); |
| 3408 | LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, ""); |
| 3409 | return LLVMBuildBitCast(g->builder, truncated_int, get_llvm_type(g, child_type), ""); |
| 3410 | } |
| 3411 | |
| 3412 | return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), ""); |
| 3401 | 3413 | } |
| 3402 | 3414 | |
| 3403 | 3415 | static bool value_is_all_undef_array(ConstExprValue *const_val, size_t len) { |