@@ -638,7 +638,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
638638 } else if (want_first_arg_sret (g, &fn_type->data .fn .fn_type_id )) {
639639 // Sret pointers must not be address 0
640640 addLLVMArgAttr (llvm_fn, 0 , " nonnull" );
641- ZigLLVMAddSretAttr (llvm_fn, 0 , get_llvm_type (g, return_type));
641+ ZigLLVMAddSretAttr (llvm_fn, get_llvm_type (g, return_type));
642642 if (cc_want_sret_attr (cc)) {
643643 addLLVMArgAttr (llvm_fn, 0 , " noalias" );
644644 }
@@ -912,10 +912,10 @@ static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr,
912912 return gen_store_untyped (g, value, ptr, alignment, ptr_type->data .pointer .is_volatile );
913913}
914914
915- static LLVMValueRef gen_load_untyped (CodeGen *g, LLVMTypeRef elem_type, LLVMValueRef ptr ,
916- uint32_t alignment, bool is_volatile, const char *name)
915+ static LLVMValueRef gen_load_untyped (CodeGen *g, LLVMValueRef ptr, uint32_t alignment, bool is_volatile ,
916+ const char *name)
917917{
918- LLVMValueRef result = LLVMBuildLoad2 (g->builder , elem_type , ptr, name);
918+ LLVMValueRef result = LLVMBuildLoad (g->builder , ptr, name);
919919 if (is_volatile) LLVMSetVolatile (result, true );
920920 if (alignment == 0 ) {
921921 LLVMSetAlignment (result, LLVMABIAlignmentOfType (g->target_data_ref , LLVMGetElementType (LLVMTypeOf (ptr))));
@@ -927,10 +927,8 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMTypeRef elem_type, LLVMValu
927927
928928static LLVMValueRef gen_load (CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) {
929929 assert (ptr_type->id == ZigTypeIdPointer);
930- ZigType *elem_type = ptr_type->data .pointer .child_type ;
931930 uint32_t alignment = get_ptr_align (g, ptr_type);
932- return gen_load_untyped (g, get_llvm_type (g, elem_type), ptr, alignment,
933- ptr_type->data .pointer .is_volatile , name);
931+ return gen_load_untyped (g, ptr, alignment, ptr_type->data .pointer .is_volatile , name);
934932}
935933
936934static LLVMValueRef get_handle_value (CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) {
@@ -1278,16 +1276,15 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
12781276 size_t len_field_index = slice_type->data .structure .fields [slice_len_index]->gen_index ;
12791277 LLVMValueRef len_field_ptr = LLVMBuildStructGEP (g->builder , addresses_field_ptr, (unsigned )len_field_index, " " );
12801278
1281- LLVMValueRef len_value = gen_load_untyped (g, usize_type_ref, len_field_ptr, 0 , false , " " );
1282- LLVMValueRef index_val = gen_load_untyped (g, usize_type_ref, index_field_ptr, 0 , false , " " );
1279+ LLVMValueRef len_value = gen_load_untyped (g, len_field_ptr, 0 , false , " " );
1280+ LLVMValueRef index_val = gen_load_untyped (g, index_field_ptr, 0 , false , " " );
12831281 LLVMValueRef len_val_minus_one = LLVMBuildSub (g->builder , len_value, LLVMConstInt (usize_type_ref, 1 , false ), " " );
12841282 LLVMValueRef masked_val = LLVMBuildAnd (g->builder , index_val, len_val_minus_one, " " );
12851283 LLVMValueRef address_indices[] = {
12861284 masked_val,
12871285 };
12881286
1289- LLVMTypeRef ptr_to_usize = LLVMPointerType (usize_type_ref, 0 );
1290- LLVMValueRef ptr_value = gen_load_untyped (g, ptr_to_usize, ptr_field_ptr, 0 , false , " " );
1287+ LLVMValueRef ptr_value = gen_load_untyped (g, ptr_field_ptr, 0 , false , " " );
12911288 LLVMValueRef address_slot = LLVMBuildInBoundsGEP (g->builder , ptr_value, address_indices, 1 , " " );
12921289
12931290 gen_store_untyped (g, address_value, address_slot, 0 , false );
@@ -5562,6 +5559,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A
55625559 size_t param_index = 0 ;
55635560 LLVMTypeRef *param_types = heap::c_allocator.allocate <LLVMTypeRef>(input_and_output_count);
55645561 LLVMValueRef *param_values = heap::c_allocator.allocate <LLVMValueRef>(input_and_output_count);
5562+ bool *param_needs_attr = heap::c_allocator.allocate <bool >(input_and_output_count);
55655563 for (size_t i = 0 ; i < asm_expr->output_list .length ; i += 1 , total_index += 1 ) {
55665564 AsmOutput *asm_output = asm_expr->output_list .at (i);
55675565 bool is_return = (asm_output->return_type != nullptr );
@@ -5619,6 +5617,8 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A
56195617
56205618 param_types[param_index] = type_ref;
56215619 param_values[param_index] = value_ref;
5620+ // In the case of indirect inputs, LLVM requires the callsite to have an elementtype(<ty>) attribute.
5621+ param_needs_attr[param_index] = buf_ptr (asm_input->constraint )[0 ] == ' *' ;
56225622 }
56235623 for (size_t i = 0 ; i < asm_expr->clobber_list .length ; i += 1 , total_index += 1 ) {
56245624 Buf *clobber_buf = asm_expr->clobber_list .at (i);
@@ -5658,14 +5658,25 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A
56585658 ret_type = get_llvm_type (g, instruction->base .value ->type );
56595659 }
56605660 LLVMTypeRef function_type = LLVMFunctionType (ret_type, param_types, (unsigned )input_and_output_count, false );
5661- heap::c_allocator.deallocate (param_types, input_and_output_count);
56625661
56635662 bool is_volatile = instruction->has_side_effects || (asm_expr->output_list .length == 0 );
56645663 LLVMValueRef asm_fn = LLVMGetInlineAsm (function_type, buf_ptr (&llvm_template), buf_len (&llvm_template),
56655664 buf_ptr (&constraint_buf), buf_len (&constraint_buf), is_volatile, false , LLVMInlineAsmDialectATT, false );
56665665
56675666 LLVMValueRef built_call = LLVMBuildCall (g->builder , asm_fn, param_values, (unsigned )input_and_output_count, " " );
5667+
5668+ for (size_t i = 0 ; i < input_and_output_count; i += 1 ) {
5669+ if (param_needs_attr[i]) {
5670+ LLVMTypeRef elem_ty = LLVMGetElementType (param_types[i]);
5671+ ZigLLVMSetCallElemTypeAttr (built_call, i, elem_ty);
5672+ }
5673+ }
5674+
5675+
5676+
5677+ heap::c_allocator.deallocate (param_types, input_and_output_count);
56685678 heap::c_allocator.deallocate (param_values, input_and_output_count);
5679+ heap::c_allocator.deallocate (param_needs_attr, input_and_output_count);
56695680 return built_call;
56705681}
56715682
0 commit comments