| ... | ... | @@ -916,9 +916,7 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMTypeRef elem_llvm_ty, LLVMV |
| 916 | 916 | { |
| 917 | 917 | LLVMValueRef result = LLVMBuildLoad2(g->builder, elem_llvm_ty, ptr, name); |
| 918 | 918 | if (is_volatile) LLVMSetVolatile(result, true); |
| 919 | | if (alignment == 0) { |
| 920 | | LLVMSetAlignment(result, LLVMABIAlignmentOfType(g->target_data_ref, LLVMGetElementType(LLVMTypeOf(ptr)))); |
| 921 | | } else { |
| 919 | if (alignment != 0) { |
| 922 | 920 | LLVMSetAlignment(result, alignment); |
| 923 | 921 | } |
| 924 | 922 | return result; |
| ... | ... | @@ -5129,7 +5127,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5129 | 5127 | |
| 5130 | 5128 | // Store a zero in the awaiter's result ptr to indicate we do not need a copy made. |
| 5131 | 5129 | LLVMValueRef awaiter_ret_ptr = LLVMBuildStructGEP2(g->builder, frame_struct_llvm_ty, frame_result_loc, frame_ret_start + 1, ""); |
| 5132 | | LLVMValueRef zero_ptr = LLVMConstNull(LLVMGetElementType(LLVMTypeOf(awaiter_ret_ptr))); |
| 5130 | LLVMValueRef zero_ptr = LLVMConstNull(LLVMGetGEPSourceElementType(awaiter_ret_ptr)); |
| 5133 | 5131 | LLVMBuildStore(g->builder, zero_ptr, awaiter_ret_ptr); |
| 5134 | 5132 | } |
| 5135 | 5133 | |
| ... | ... | @@ -5147,7 +5145,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5147 | 5145 | |
| 5148 | 5146 | LLVMValueRef fn_ptr_ptr = LLVMBuildStructGEP2(g->builder, frame_struct_llvm_ty, frame_result_loc, frame_fn_ptr_index, ""); |
| 5149 | 5147 | LLVMValueRef bitcasted_fn_val = LLVMBuildBitCast(g->builder, fn_val, |
| 5150 | | LLVMGetElementType(LLVMTypeOf(fn_ptr_ptr)), ""); |
| 5148 | LLVMGetGEPSourceElementType(fn_ptr_ptr), ""); |
| 5151 | 5149 | LLVMBuildStore(g->builder, bitcasted_fn_val, fn_ptr_ptr); |
| 5152 | 5150 | |
| 5153 | 5151 | LLVMValueRef resume_index_ptr = LLVMBuildStructGEP2(g->builder, frame_struct_llvm_ty, frame_result_loc, frame_resume_index, ""); |
| ... | ... | @@ -5266,8 +5264,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5266 | 5264 | size_t field_count = arg_calc.field_index; |
| 5267 | 5265 | |
| 5268 | 5266 | LLVMTypeRef *field_types = heap::c_allocator.allocate_nonzero<LLVMTypeRef>(field_count); |
| 5269 | | LLVMGetStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc)), field_types); |
| 5270 | | assert(LLVMCountStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc))) == arg_calc_start.field_index); |
| 5267 | LLVMGetStructElementTypes(frame_struct_llvm_ty, field_types); |
| 5268 | assert(LLVMCountStructElementTypes(frame_struct_llvm_ty) == arg_calc_start.field_index); |
| 5271 | 5269 | |
| 5272 | 5270 | arg_calc = arg_calc_start; |
| 5273 | 5271 | for (size_t arg_i = 0; arg_i < gen_param_values.length; arg_i += 1) { |
| ... | ... | @@ -5648,7 +5646,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5648 | 5646 | size_t param_index = 0; |
| 5649 | 5647 | LLVMTypeRef *param_types = heap::c_allocator.allocate<LLVMTypeRef>(input_and_output_count); |
| 5650 | 5648 | LLVMValueRef *param_values = heap::c_allocator.allocate<LLVMValueRef>(input_and_output_count); |
| 5651 | | bool *param_needs_attr = heap::c_allocator.allocate<bool>(input_and_output_count); |
| 5649 | LLVMTypeRef *param_needs_attr = heap::c_allocator.allocate<LLVMTypeRef>(input_and_output_count); |
| 5652 | 5650 | for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) { |
| 5653 | 5651 | AsmOutput *asm_output = asm_expr->output_list.at(i); |
| 5654 | 5652 | bool is_return = (asm_output->return_type != nullptr); |
| ... | ... | @@ -5664,7 +5662,8 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5664 | 5662 | buf_appendf(&constraint_buf, "=%s", buf_ptr(asm_output->constraint) + 1); |
| 5665 | 5663 | } else { |
| 5666 | 5664 | buf_appendf(&constraint_buf, "=*%s", buf_ptr(asm_output->constraint) + 1); |
| 5667 | | param_needs_attr[param_index] = true; |
| 5665 | ZigVar *variable = instruction->output_vars[i]; |
| 5666 | param_needs_attr[param_index] = get_llvm_type(g, variable->var_type); |
| 5668 | 5667 | } |
| 5669 | 5668 | if (total_index + 1 < total_constraint_count) { |
| 5670 | 5669 | buf_append_char(&constraint_buf, ','); |
| ... | ... | @@ -5690,6 +5689,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5690 | 5689 | ZigType *const type = ir_input->value->type; |
| 5691 | 5690 | LLVMTypeRef type_ref = get_llvm_type(g, type); |
| 5692 | 5691 | LLVMValueRef value_ref = ir_llvm_value(g, ir_input); |
| 5692 | LLVMTypeRef elem_type_ref = nullptr; |
| 5693 | 5693 | // Handle integers of non pot bitsize by widening them. |
| 5694 | 5694 | if (type->id == ZigTypeIdInt) { |
| 5695 | 5695 | const size_t bitsize = type->data.integral.bit_count; |
| ... | ... | @@ -5701,6 +5701,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5701 | 5701 | value_ref = gen_widen_or_shorten(g, false, type, wider_type, value_ref); |
| 5702 | 5702 | } |
| 5703 | 5703 | } else if (handle_is_ptr(g, type)) { |
| 5704 | elem_type_ref = type_ref; |
| 5704 | 5705 | ZigType *gen_type = get_pointer_to_type(g, type, true); |
| 5705 | 5706 | type_ref = get_llvm_type(g, gen_type); |
| 5706 | 5707 | } |
| ... | ... | @@ -5708,7 +5709,9 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5708 | 5709 | param_types[param_index] = type_ref; |
| 5709 | 5710 | param_values[param_index] = value_ref; |
| 5710 | 5711 | // In the case of indirect inputs, LLVM requires the callsite to have an elementtype(<ty>) attribute. |
| 5711 | | param_needs_attr[param_index] = buf_ptr(asm_input->constraint)[0] == '*'; |
| 5712 | if (buf_ptr(asm_input->constraint)[0] == '*') { |
| 5713 | param_needs_attr[param_index] = elem_type_ref; |
| 5714 | } |
| 5712 | 5715 | } |
| 5713 | 5716 | for (size_t i = 0; i < asm_expr->clobber_list.length; i += 1, total_index += 1) { |
| 5714 | 5717 | Buf *clobber_buf = asm_expr->clobber_list.at(i); |
| ... | ... | @@ -5756,8 +5759,8 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5756 | 5759 | LLVMValueRef built_call = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(asm_fn), asm_fn, param_values, (unsigned)input_and_output_count, ""); |
| 5757 | 5760 | |
| 5758 | 5761 | for (size_t i = 0; i < input_and_output_count; i += 1) { |
| 5759 | | if (param_needs_attr[i]) { |
| 5760 | | LLVMTypeRef elem_ty = LLVMGetElementType(param_types[i]); |
| 5762 | if (param_needs_attr[i] != nullptr) { |
| 5763 | LLVMTypeRef elem_ty = param_needs_attr[i]; |
| 5761 | 5764 | ZigLLVMSetCallElemTypeAttr(built_call, i, elem_ty); |
| 5762 | 5765 | } |
| 5763 | 5766 | } |
| ... | ... | @@ -7665,7 +7668,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, Stage1Air *executable, Stage1Air |
| 7665 | 7668 | target_frame_ptr, frame_ret_start + 1, ""); |
| 7666 | 7669 | if (result_loc == nullptr) { |
| 7667 | 7670 | // no copy needed |
| 7668 | | LLVMBuildStore(g->builder, LLVMConstNull(LLVMGetElementType(LLVMTypeOf(awaiter_ret_ptr_ptr))), |
| 7671 | LLVMBuildStore(g->builder, LLVMConstNull(LLVMGetGEPSourceElementType(awaiter_ret_ptr_ptr)), |
| 7669 | 7672 | awaiter_ret_ptr_ptr); |
| 7670 | 7673 | } else { |
| 7671 | 7674 | LLVMBuildStore(g->builder, result_loc, awaiter_ret_ptr_ptr); |
| ... | ... | @@ -9440,7 +9443,7 @@ static void do_code_gen(CodeGen *g) { |
| 9440 | 9443 | get_llvm_type(g, get_fn_frame_type(g, g->cur_fn)), |
| 9441 | 9444 | g->cur_frame_ptr, |
| 9442 | 9445 | frame_index_trace_arg(g, fn_type_id->return_type), ""); |
| 9443 | | LLVMValueRef zero_ptr = LLVMConstNull(LLVMGetElementType(LLVMTypeOf(trace_ptr_ptr))); |
| 9446 | LLVMValueRef zero_ptr = LLVMConstNull(LLVMGetGEPSourceElementType(trace_ptr_ptr)); |
| 9444 | 9447 | LLVMBuildStore(g->builder, zero_ptr, trace_ptr_ptr); |
| 9445 | 9448 | } |
| 9446 | 9449 | |