| ... | @@ -111,16 +111,6 @@ static TypeTableEntry *get_expr_type(AstNode *node) { | ... | @@ -111,16 +111,6 @@ static TypeTableEntry *get_expr_type(AstNode *node) { |
| 111 | return get_resolved_expr(node)->type_entry; | 111 | return get_resolved_expr(node)->type_entry; |
| 112 | } | 112 | } |
| 113 | | 113 | |
| 114 | static TypeTableEntry *fn_proto_type_from_type_node(CodeGen *g, AstNode *type_node) { | | |
| 115 | TypeTableEntry *type_entry = get_type_for_type_node(type_node); | | |
| 116 | | | |
| 117 | if (handle_is_ptr(type_entry)) { | | |
| 118 | return get_pointer_to_type(g, type_entry, true); | | |
| 119 | } else { | | |
| 120 | return type_entry; | | |
| 121 | } | | |
| 122 | } | | |
| 123 | | | |
| 124 | enum AddSubMul { | 114 | enum AddSubMul { |
| 125 | AddSubMulAdd = 0, | 115 | AddSubMulAdd = 0, |
| 126 | AddSubMulSub = 1, | 116 | AddSubMulSub = 1, |
| ... | @@ -2774,14 +2764,15 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2774,14 +2764,15 @@ static void do_code_gen(CodeGen *g) { |
| 2774 | continue; | 2764 | continue; |
| 2775 | } | 2765 | } |
| 2776 | | 2766 | |
| 2777 | AstNode *type_node = param_node->data.param_decl.type; | 2767 | TypeTableEntry *param_type = info->type; |
| 2778 | TypeTableEntry *param_type = fn_proto_type_from_type_node(g, type_node); | | |
| 2779 | LLVMValueRef argument_val = LLVMGetParam(fn_table_entry->fn_value, gen_index); | 2768 | LLVMValueRef argument_val = LLVMGetParam(fn_table_entry->fn_value, gen_index); |
| 2780 | bool param_is_noalias = param_node->data.param_decl.is_noalias; | 2769 | bool param_is_noalias = param_node->data.param_decl.is_noalias; |
| 2781 | if (param_type->id == TypeTableEntryIdPointer && param_is_noalias) { | 2770 | if (param_type->id == TypeTableEntryIdPointer && param_is_noalias) { |
| 2782 | LLVMAddAttribute(argument_val, LLVMNoAliasAttribute); | 2771 | LLVMAddAttribute(argument_val, LLVMNoAliasAttribute); |
| 2783 | } | 2772 | } |
| 2784 | if (param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) { | 2773 | if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || |
| | 2774 | is_byval) |
| | 2775 | { |
| 2785 | LLVMAddAttribute(argument_val, LLVMReadOnlyAttribute); | 2776 | LLVMAddAttribute(argument_val, LLVMReadOnlyAttribute); |
| 2786 | } | 2777 | } |
| 2787 | if (param_type->id == TypeTableEntryIdPointer) { | 2778 | if (param_type->id == TypeTableEntryIdPointer) { |
| ... | @@ -2789,7 +2780,8 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2789,7 +2780,8 @@ static void do_code_gen(CodeGen *g) { |
| 2789 | // non null attribute here | 2780 | // non null attribute here |
| 2790 | } | 2781 | } |
| 2791 | if (is_byval) { | 2782 | if (is_byval) { |
| 2792 | LLVMAddAttribute(argument_val, LLVMByValAttribute); | 2783 | // TODO |
| | 2784 | //LLVMAddAttribute(argument_val, LLVMByValAttribute); |
| 2793 | } | 2785 | } |
| 2794 | } | 2786 | } |
| 2795 | | 2787 | |
| ... | @@ -2847,6 +2839,7 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2847,6 +2839,7 @@ static void do_code_gen(CodeGen *g) { |
| 2847 | | 2839 | |
| 2848 | unsigned tag; | 2840 | unsigned tag; |
| 2849 | unsigned arg_no; | 2841 | unsigned arg_no; |
| | 2842 | TypeTableEntry *gen_type; |
| 2850 | if (block_context->node->type == NodeTypeFnDef) { | 2843 | if (block_context->node->type == NodeTypeFnDef) { |
| 2851 | tag = LLVMZigTag_DW_arg_variable(); | 2844 | tag = LLVMZigTag_DW_arg_variable(); |
| 2852 | arg_no = var->gen_arg_index + 1; | 2845 | arg_no = var->gen_arg_index + 1; |
| ... | @@ -2854,6 +2847,8 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2854,6 +2847,8 @@ static void do_code_gen(CodeGen *g) { |
| 2854 | var->is_ptr = false; | 2847 | var->is_ptr = false; |
| 2855 | assert(var->gen_arg_index >= 0); | 2848 | assert(var->gen_arg_index >= 0); |
| 2856 | var->value_ref = LLVMGetParam(fn, var->gen_arg_index); | 2849 | var->value_ref = LLVMGetParam(fn, var->gen_arg_index); |
| | 2850 | |
| | 2851 | gen_type = fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index].type; |
| 2857 | } else { | 2852 | } else { |
| 2858 | tag = LLVMZigTag_DW_auto_variable(); | 2853 | tag = LLVMZigTag_DW_auto_variable(); |
| 2859 | arg_no = 0; | 2854 | arg_no = 0; |
| ... | @@ -2862,12 +2857,14 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -2862,12 +2857,14 @@ static void do_code_gen(CodeGen *g) { |
| 2862 | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); | 2857 | var->value_ref = LLVMBuildAlloca(g->builder, var->type->type_ref, buf_ptr(&var->name)); |
| 2863 | uint64_t align_bytes = LLVMABISizeOfType(g->target_data_ref, var->type->type_ref); | 2858 | uint64_t align_bytes = LLVMABISizeOfType(g->target_data_ref, var->type->type_ref); |
| 2864 | LLVMSetAlignment(var->value_ref, align_bytes); | 2859 | LLVMSetAlignment(var->value_ref, align_bytes); |
| | 2860 | |
| | 2861 | gen_type = var->type; |
| 2865 | } | 2862 | } |
| 2866 | | 2863 | |
| 2867 | var->di_loc_var = LLVMZigCreateLocalVariable(g->dbuilder, tag, | 2864 | var->di_loc_var = LLVMZigCreateLocalVariable(g->dbuilder, tag, |
| 2868 | block_context->di_scope, buf_ptr(&var->name), | 2865 | block_context->di_scope, buf_ptr(&var->name), |
| 2869 | import->di_file, var->decl_node->line + 1, | 2866 | import->di_file, var->decl_node->line + 1, |
| 2870 | var->type->di_type, !g->strip_debug_symbols, 0, arg_no); | 2867 | gen_type->di_type, !g->strip_debug_symbols, 0, arg_no); |
| 2871 | } | 2868 | } |
| 2872 | | 2869 | |
| 2873 | // allocate structs which are the result of casts | 2870 | // allocate structs which are the result of casts |