diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-08-26 14:35:34 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-08-26 14:35:34 +0200 |
| commit | 29df0ca39db8c336d6bdc7090f6d5f51b7463602 (patch) | |
| tree | 8f26542420e73f0588c6d4f167711a318fb23dfd /src/stage1/codegen.cpp | |
| parent | 570c75cb7440935990338ee733cce4a0b966c57b (diff) | |
| parent | 9c95f38a7c1defc7f63a4815bfc2d76a5f9f83f6 (diff) | |
| download | zig-29df0ca39db8c336d6bdc7090f6d5f51b7463602.tar.gz zig-29df0ca39db8c336d6bdc7090f6d5f51b7463602.zip | |
Merge remote-tracking branch 'origin/master' into zld-incr
Diffstat (limited to 'src/stage1/codegen.cpp')
| -rw-r--r-- | src/stage1/codegen.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 359af18e82..c44081c770 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -3831,10 +3831,14 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, Stage1Air *executable, LLVMValueRef shift_amt_val = LLVMConstInt(LLVMTypeOf(containing_int), shift_amt, false); LLVMValueRef shifted_value = LLVMBuildLShr(g->builder, containing_int, shift_amt_val, ""); + LLVMTypeRef same_size_int = LLVMIntType(size_in_bits); + LLVMValueRef mask = LLVMConstAllOnes(LLVMIntType(size_in_bits)); + mask = LLVMConstZExt(mask, LLVMTypeOf(containing_int)); + LLVMValueRef masked_value = LLVMBuildAnd(g->builder, shifted_value, mask, ""); + if (handle_is_ptr(g, child_type)) { LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc); - LLVMTypeRef same_size_int = LLVMIntType(size_in_bits); - LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, ""); + LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, masked_value, same_size_int, ""); LLVMValueRef bitcasted_ptr = LLVMBuildBitCast(g->builder, result_loc, LLVMPointerType(same_size_int, 0), ""); LLVMBuildStore(g->builder, truncated_int, bitcasted_ptr); @@ -3842,12 +3846,11 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, Stage1Air *executable, } if (child_type->id == ZigTypeIdFloat) { - LLVMTypeRef same_size_int = LLVMIntType(size_in_bits); - LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, shifted_value, same_size_int, ""); + LLVMValueRef truncated_int = LLVMBuildTrunc(g->builder, masked_value, same_size_int, ""); return LLVMBuildBitCast(g->builder, truncated_int, get_llvm_type(g, child_type), ""); } - return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), ""); + return LLVMBuildTrunc(g->builder, masked_value, get_llvm_type(g, child_type), ""); } static bool value_is_all_undef_array(CodeGen *g, ZigValue *const_val, size_t len) { |
