| ... | ... | @@ -104,8 +104,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 104 | 104 | static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); |
| 105 | 105 | static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 106 | 106 | IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type); |
| 107 | | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 108 | | VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr); |
| 107 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var); |
| 109 | 108 | static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); |
| 110 | 109 | static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval); |
| 111 | 110 | |
| ... | ... | @@ -1000,13 +999,9 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in |
| 1000 | 999 | return new_instruction; |
| 1001 | 1000 | } |
| 1002 | 1001 | |
| 1003 | | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, |
| 1004 | | VariableTableEntry *var, bool is_const, bool is_volatile) |
| 1005 | | { |
| 1002 | static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) { |
| 1006 | 1003 | IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node); |
| 1007 | 1004 | instruction->var = var; |
| 1008 | | instruction->is_const = is_const; |
| 1009 | | instruction->is_volatile = is_volatile; |
| 1010 | 1005 | |
| 1011 | 1006 | ir_ref_var(var); |
| 1012 | 1007 | |
| ... | ... | @@ -3515,8 +3510,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3515 | 3510 | |
| 3516 | 3511 | VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); |
| 3517 | 3512 | if (var) { |
| 3518 | | IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var, |
| 3519 | | !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile); |
| 3513 | IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var); |
| 3520 | 3514 | if (lval.is_ptr) |
| 3521 | 3515 | return var_ptr; |
| 3522 | 3516 | else |
| ... | ... | @@ -5140,7 +5134,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5140 | 5134 | |
| 5141 | 5135 | IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); |
| 5142 | 5136 | ir_build_var_decl(irb, child_scope, elem_node, elem_var, elem_var_type, nullptr, undefined_value); |
| 5143 | | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var, false, false); |
| 5137 | IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); |
| 5144 | 5138 | |
| 5145 | 5139 | AstNode *index_var_source_node; |
| 5146 | 5140 | VariableTableEntry *index_var; |
| ... | ... | @@ -5158,7 +5152,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 5158 | 5152 | IrInstruction *zero = ir_build_const_usize(irb, child_scope, node, 0); |
| 5159 | 5153 | IrInstruction *one = ir_build_const_usize(irb, child_scope, node, 1); |
| 5160 | 5154 | ir_build_var_decl(irb, child_scope, index_var_source_node, index_var, usize, nullptr, zero); |
| 5161 | | IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var, false, false); |
| 5155 | IrInstruction *index_ptr = ir_build_var_ptr(irb, child_scope, node, index_var); |
| 5162 | 5156 | |
| 5163 | 5157 | |
| 5164 | 5158 | IrBasicBlock *cond_block = ir_create_basic_block(irb, child_scope, "ForCond"); |
| ... | ... | @@ -6387,7 +6381,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *parent_scope, Ast |
| 6387 | 6381 | IrInstruction *promise_result_type = ir_build_promise_result_type(irb, parent_scope, node, target_promise_type); |
| 6388 | 6382 | ir_build_await_bookkeeping(irb, parent_scope, node, promise_result_type); |
| 6389 | 6383 | ir_build_var_decl(irb, parent_scope, node, result_var, promise_result_type, nullptr, undefined_value); |
| 6390 | | IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var, false, false); |
| 6384 | IrInstruction *my_result_var_ptr = ir_build_var_ptr(irb, parent_scope, node, result_var); |
| 6391 | 6385 | ir_build_store_ptr(irb, parent_scope, node, result_ptr_field_ptr, my_result_var_ptr); |
| 6392 | 6386 | IrInstruction *save_token = ir_build_coro_save(irb, parent_scope, node, irb->exec->coro_handle); |
| 6393 | 6387 | IrInstruction *promise_type_val = ir_build_const_type(irb, parent_scope, node, |
| ... | ... | @@ -6708,15 +6702,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6708 | 6702 | IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); |
| 6709 | 6703 | // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa |
| 6710 | 6704 | ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); |
| 6711 | | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var, false, false); |
| 6705 | coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); |
| 6712 | 6706 | |
| 6713 | 6707 | VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); |
| 6714 | 6708 | IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); |
| 6715 | 6709 | IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, |
| 6716 | 6710 | get_maybe_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); |
| 6717 | 6711 | ir_build_var_decl(irb, coro_scope, node, await_handle_var, await_handle_type_val, nullptr, null_value); |
| 6718 | | irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, |
| 6719 | | await_handle_var, false, false); |
| 6712 | irb->exec->await_handle_var_ptr = ir_build_var_ptr(irb, coro_scope, node, await_handle_var); |
| 6720 | 6713 | |
| 6721 | 6714 | u8_ptr_type = ir_build_const_type(irb, coro_scope, node, |
| 6722 | 6715 | get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false)); |
| ... | ... | @@ -6856,7 +6849,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec |
| 6856 | 6849 | IrInstruction *coro_mem_ptr_maybe = ir_build_coro_free(irb, scope, node, coro_id, irb->exec->coro_handle); |
| 6857 | 6850 | IrInstruction *coro_mem_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_mem_ptr_maybe); |
| 6858 | 6851 | IrInstruction *coro_mem_ptr_ref = ir_build_ref(irb, scope, node, coro_mem_ptr, true, false); |
| 6859 | | IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var, true, false); |
| 6852 | IrInstruction *coro_size_ptr = ir_build_var_ptr(irb, scope, node, coro_size_var); |
| 6860 | 6853 | IrInstruction *coro_size = ir_build_load_ptr(irb, scope, node, coro_size_ptr); |
| 6861 | 6854 | IrInstruction *mem_slice = ir_build_slice(irb, scope, node, coro_mem_ptr_ref, zero, coro_size, false); |
| 6862 | 6855 | size_t arg_count = 2; |
| ... | ... | @@ -8958,35 +8951,15 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 8958 | 8951 | ConstExprValue *pointee, TypeTableEntry *pointee_type, |
| 8959 | 8952 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 8960 | 8953 | { |
| 8961 | | // TODO remove this special case for types |
| 8962 | | if (pointee_type->id == TypeTableEntryIdMetaType) { |
| 8963 | | TypeTableEntry *type_entry = pointee->data.x_type; |
| 8964 | | if (type_entry->id == TypeTableEntryIdUnreachable) { |
| 8965 | | ir_add_error(ira, instruction, buf_sprintf("pointer to noreturn not allowed")); |
| 8966 | | return ira->codegen->invalid_instruction; |
| 8967 | | } |
| 8968 | | |
| 8969 | | IrInstruction *const_instr = ir_get_const(ira, instruction); |
| 8970 | | ConstExprValue *const_val = &const_instr->value; |
| 8971 | | const_val->type = pointee_type; |
| 8972 | | type_ensure_zero_bits_known(ira->codegen, type_entry); |
| 8973 | | if (type_is_invalid(type_entry)) { |
| 8974 | | return ira->codegen->invalid_instruction; |
| 8975 | | } |
| 8976 | | const_val->data.x_type = get_pointer_to_type_extra(ira->codegen, type_entry, |
| 8977 | | ptr_is_const, ptr_is_volatile, get_abi_alignment(ira->codegen, type_entry), 0, 0); |
| 8978 | | return const_instr; |
| 8979 | | } else { |
| 8980 | | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 8981 | | ptr_is_const, ptr_is_volatile, ptr_align, 0, 0); |
| 8982 | | IrInstruction *const_instr = ir_get_const(ira, instruction); |
| 8983 | | ConstExprValue *const_val = &const_instr->value; |
| 8984 | | const_val->type = ptr_type; |
| 8985 | | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 8986 | | const_val->data.x_ptr.mut = ptr_mut; |
| 8987 | | const_val->data.x_ptr.data.ref.pointee = pointee; |
| 8988 | | return const_instr; |
| 8989 | | } |
| 8954 | TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 8955 | ptr_is_const, ptr_is_volatile, ptr_align, 0, 0); |
| 8956 | IrInstruction *const_instr = ir_get_const(ira, instruction); |
| 8957 | ConstExprValue *const_val = &const_instr->value; |
| 8958 | const_val->type = ptr_type; |
| 8959 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 8960 | const_val->data.x_ptr.mut = ptr_mut; |
| 8961 | const_val->data.x_ptr.data.ref.pointee = pointee; |
| 8962 | return const_instr; |
| 8990 | 8963 | } |
| 8991 | 8964 | |
| 8992 | 8965 | static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| ... | ... | @@ -9314,9 +9287,8 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 9314 | 9287 | ConstExprValue *val = ir_resolve_const(ira, value, UndefOk); |
| 9315 | 9288 | if (!val) |
| 9316 | 9289 | return ira->codegen->invalid_instruction; |
| 9317 | | bool final_is_const = (value->value.type->id == TypeTableEntryIdMetaType) ? is_const : true; |
| 9318 | 9290 | return ir_get_const_ptr(ira, source_instruction, val, value->value.type, |
| 9319 | | ConstPtrMutComptimeConst, final_is_const, is_volatile, |
| 9291 | ConstPtrMutComptimeConst, is_const, is_volatile, |
| 9320 | 9292 | get_abi_alignment(ira->codegen, value->value.type)); |
| 9321 | 9293 | } |
| 9322 | 9294 | |
| ... | ... | @@ -10245,21 +10217,6 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 10245 | 10217 | source_instruction->source_node, ptr); |
| 10246 | 10218 | load_ptr_instruction->value.type = child_type; |
| 10247 | 10219 | return load_ptr_instruction; |
| 10248 | | } else if (type_entry->id == TypeTableEntryIdMetaType) { |
| 10249 | | ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad); |
| 10250 | | if (!ptr_val) |
| 10251 | | return ira->codegen->invalid_instruction; |
| 10252 | | |
| 10253 | | TypeTableEntry *ptr_type = ptr_val->data.x_type; |
| 10254 | | if (ptr_type->id == TypeTableEntryIdPointer) { |
| 10255 | | TypeTableEntry *child_type = ptr_type->data.pointer.child_type; |
| 10256 | | return ir_create_const_type(&ira->new_irb, source_instruction->scope, |
| 10257 | | source_instruction->source_node, child_type); |
| 10258 | | } else { |
| 10259 | | ir_add_error(ira, source_instruction, |
| 10260 | | buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr_type->name))); |
| 10261 | | return ira->codegen->invalid_instruction; |
| 10262 | | } |
| 10263 | 10220 | } else { |
| 10264 | 10221 | ir_add_error_node(ira, source_instruction->source_node, |
| 10265 | 10222 | buf_sprintf("attempt to dereference non pointer type '%s'", |
| ... | ... | @@ -11966,7 +11923,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i |
| 11966 | 11923 | { |
| 11967 | 11924 | VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var; |
| 11968 | 11925 | assert(coro_allocator_var != nullptr); |
| 11969 | | IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var, true, false); |
| 11926 | IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var); |
| 11970 | 11927 | IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst); |
| 11971 | 11928 | assert(result->value.type != nullptr); |
| 11972 | 11929 | return result; |
| ... | ... | @@ -12147,7 +12104,7 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in |
| 12147 | 12104 | } |
| 12148 | 12105 | |
| 12149 | 12106 | static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 12150 | | VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr) |
| 12107 | VariableTableEntry *var) |
| 12151 | 12108 | { |
| 12152 | 12109 | if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) { |
| 12153 | 12110 | assert(ira->codegen->errors.length != 0); |
| ... | ... | @@ -12173,8 +12130,8 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 12173 | 12130 | } |
| 12174 | 12131 | } |
| 12175 | 12132 | |
| 12176 | | bool is_const = (var->value->type->id == TypeTableEntryIdMetaType) ? is_const_ptr : var->src_is_const; |
| 12177 | | bool is_volatile = (var->value->type->id == TypeTableEntryIdMetaType) ? is_volatile_ptr : false; |
| 12133 | bool is_const = var->src_is_const; |
| 12134 | bool is_volatile = false; |
| 12178 | 12135 | if (mem_slot != nullptr) { |
| 12179 | 12136 | switch (mem_slot->special) { |
| 12180 | 12137 | case ConstValSpecialRuntime: |
| ... | ... | @@ -12200,7 +12157,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 12200 | 12157 | no_mem_slot: |
| 12201 | 12158 | |
| 12202 | 12159 | IrInstruction *var_ptr_instruction = ir_build_var_ptr(&ira->new_irb, |
| 12203 | | instruction->scope, instruction->source_node, var, is_const, is_volatile); |
| 12160 | instruction->scope, instruction->source_node, var); |
| 12204 | 12161 | var_ptr_instruction->value.type = get_pointer_to_type_extra(ira->codegen, var->value->type, |
| 12205 | 12162 | var->src_is_const, is_volatile, var->align_bytes, 0, 0); |
| 12206 | 12163 | type_ensure_zero_bits_known(ira->codegen, var->value->type); |
| ... | ... | @@ -12486,7 +12443,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal |
| 12486 | 12443 | buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); |
| 12487 | 12444 | return ira->codegen->builtin_types.entry_invalid; |
| 12488 | 12445 | } |
| 12489 | | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var, true, false); |
| 12446 | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var); |
| 12490 | 12447 | if (type_is_invalid(arg_var_ptr_inst->value.type)) |
| 12491 | 12448 | return ira->codegen->builtin_types.entry_invalid; |
| 12492 | 12449 | |
| ... | ... | @@ -13120,17 +13077,16 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP |
| 13120 | 13077 | } |
| 13121 | 13078 | |
| 13122 | 13079 | static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 13123 | | VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr) |
| 13080 | VariableTableEntry *var) |
| 13124 | 13081 | { |
| 13125 | | IrInstruction *result = ir_get_var_ptr(ira, instruction, var, is_const_ptr, is_volatile_ptr); |
| 13082 | IrInstruction *result = ir_get_var_ptr(ira, instruction, var); |
| 13126 | 13083 | ir_link_new_instruction(result, instruction); |
| 13127 | 13084 | return result->value.type; |
| 13128 | 13085 | } |
| 13129 | 13086 | |
| 13130 | 13087 | static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) { |
| 13131 | 13088 | VariableTableEntry *var = var_ptr_instruction->var; |
| 13132 | | return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var, var_ptr_instruction->is_const, |
| 13133 | | var_ptr_instruction->is_volatile); |
| 13089 | return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var); |
| 13134 | 13090 | } |
| 13135 | 13091 | |
| 13136 | 13092 | static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) { |
| ... | ... | @@ -13152,11 +13108,6 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 13152 | 13108 | return ira->codegen->builtin_types.entry_invalid; |
| 13153 | 13109 | |
| 13154 | 13110 | TypeTableEntry *ptr_type = array_ptr->value.type; |
| 13155 | | if (ptr_type->id == TypeTableEntryIdMetaType) { |
| 13156 | | ir_add_error(ira, &elem_ptr_instruction->base, |
| 13157 | | buf_sprintf("array access of non-array type '%s'", buf_ptr(&ptr_type->name))); |
| 13158 | | return ira->codegen->builtin_types.entry_invalid; |
| 13159 | | } |
| 13160 | 13111 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 13161 | 13112 | |
| 13162 | 13113 | TypeTableEntry *array_type = ptr_type->data.pointer.child_type; |
| ... | ... | @@ -13218,8 +13169,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 13218 | 13169 | bool is_const = true; |
| 13219 | 13170 | bool is_volatile = false; |
| 13220 | 13171 | if (var) { |
| 13221 | | return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var, |
| 13222 | | is_const, is_volatile); |
| 13172 | return ir_analyze_var_ptr(ira, &elem_ptr_instruction->base, var); |
| 13223 | 13173 | } else { |
| 13224 | 13174 | return ir_analyze_const_ptr(ira, &elem_ptr_instruction->base, &ira->codegen->const_void_val, |
| 13225 | 13175 | ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile); |
| ... | ... | @@ -13603,7 +13553,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source |
| 13603 | 13553 | add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); |
| 13604 | 13554 | } |
| 13605 | 13555 | |
| 13606 | | return ir_analyze_var_ptr(ira, source_instruction, var, false, false); |
| 13556 | return ir_analyze_var_ptr(ira, source_instruction, var); |
| 13607 | 13557 | } |
| 13608 | 13558 | case TldIdFn: |
| 13609 | 13559 | { |
| ... | ... | @@ -13652,14 +13602,8 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 13652 | 13602 | if (type_is_invalid(container_ptr->value.type)) |
| 13653 | 13603 | return ira->codegen->builtin_types.entry_invalid; |
| 13654 | 13604 | |
| 13655 | | TypeTableEntry *container_type; |
| 13656 | | if (container_ptr->value.type->id == TypeTableEntryIdPointer) { |
| 13657 | | container_type = container_ptr->value.type->data.pointer.child_type; |
| 13658 | | } else if (container_ptr->value.type->id == TypeTableEntryIdMetaType) { |
| 13659 | | container_type = container_ptr->value.type; |
| 13660 | | } else { |
| 13661 | | zig_unreachable(); |
| 13662 | | } |
| 13605 | TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type; |
| 13606 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 13663 | 13607 | |
| 13664 | 13608 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 13665 | 13609 | if (!field_name) { |
| ... | ... | @@ -13732,17 +13676,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 13732 | 13676 | if (!container_ptr_val) |
| 13733 | 13677 | return ira->codegen->builtin_types.entry_invalid; |
| 13734 | 13678 | |
| 13735 | | TypeTableEntry *child_type; |
| 13736 | | if (container_ptr->value.type->id == TypeTableEntryIdMetaType) { |
| 13737 | | TypeTableEntry *ptr_type = container_ptr_val->data.x_type; |
| 13738 | | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 13739 | | child_type = ptr_type->data.pointer.child_type; |
| 13740 | | } else if (container_ptr->value.type->id == TypeTableEntryIdPointer) { |
| 13741 | | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 13742 | | child_type = child_val->data.x_type; |
| 13743 | | } else { |
| 13744 | | zig_unreachable(); |
| 13745 | | } |
| 13679 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 13680 | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 13681 | TypeTableEntry *child_type = child_val->data.x_type; |
| 13746 | 13682 | |
| 13747 | 13683 | if (type_is_invalid(child_type)) { |
| 13748 | 13684 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -17337,8 +17273,11 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 17337 | 17273 | if (array_type->data.array.len == 0 && byte_alignment == 0) { |
| 17338 | 17274 | byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); |
| 17339 | 17275 | } |
| 17276 | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 17277 | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 17340 | 17278 | TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, |
| 17341 | | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 17279 | ptr_type->data.pointer.is_const || is_comptime_const, |
| 17280 | ptr_type->data.pointer.is_volatile, |
| 17342 | 17281 | byte_alignment, 0, 0); |
| 17343 | 17282 | return_type = get_slice_type(ira->codegen, slice_ptr_type); |
| 17344 | 17283 | } else if (array_type->id == TypeTableEntryIdPointer) { |
| ... | ... | @@ -17525,6 +17464,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns |
| 17525 | 17464 | return ira->codegen->builtin_types.entry_invalid; |
| 17526 | 17465 | TypeTableEntry *container_type = ir_resolve_type(ira, container); |
| 17527 | 17466 | |
| 17467 | ensure_complete_type(ira->codegen, container_type); |
| 17468 | if (type_is_invalid(container_type)) |
| 17469 | return ira->codegen->builtin_types.entry_invalid; |
| 17470 | |
| 17528 | 17471 | uint64_t result; |
| 17529 | 17472 | if (type_is_invalid(container_type)) { |
| 17530 | 17473 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -17912,15 +17855,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 17912 | 17855 | return ira->codegen->builtin_types.entry_invalid; |
| 17913 | 17856 | TypeTableEntry *ptr_type = value->value.type; |
| 17914 | 17857 | |
| 17915 | | // Because we don't have Pointer Reform yet, we can't have a pointer to a 'type'. |
| 17916 | | // Therefor, we have to check for type 'type' here, so we can output a correct error |
| 17917 | | // without asserting the assert below. |
| 17918 | | if (ptr_type->id == TypeTableEntryIdMetaType) { |
| 17919 | | ir_add_error(ira, value, |
| 17920 | | buf_sprintf("expected error union type, found '%s'", buf_ptr(&ptr_type->name))); |
| 17921 | | return ira->codegen->builtin_types.entry_invalid; |
| 17922 | | } |
| 17923 | | |
| 17924 | 17858 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 17925 | 17859 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 17926 | 17860 | |
| ... | ... | @@ -18697,8 +18631,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 18697 | 18631 | TldVar *tld_var = (TldVar *)tld; |
| 18698 | 18632 | VariableTableEntry *var = tld_var->var; |
| 18699 | 18633 | |
| 18700 | | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var, |
| 18701 | | !lval.is_ptr || lval.is_const, lval.is_ptr && lval.is_volatile); |
| 18634 | IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); |
| 18702 | 18635 | if (type_is_invalid(var_ptr->value.type)) |
| 18703 | 18636 | return ira->codegen->builtin_types.entry_invalid; |
| 18704 | 18637 | |