| ... | ... | @@ -10982,6 +10982,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 10982 | 10982 | ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 10983 | 10983 | { |
| 10984 | 10984 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, &ptr->value); |
| 10985 | if (!pointee) return ira->codegen->invalid_instruction; |
| 10985 | 10986 | if (pointee->special != ConstValSpecialRuntime) { |
| 10986 | 10987 | IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope, |
| 10987 | 10988 | source_instruction->source_node, child_type); |
| ... | ... | @@ -13655,6 +13656,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp |
| 13655 | 13656 | return ira->codegen->builtin_types.entry_invalid; |
| 13656 | 13657 | |
| 13657 | 13658 | ConstExprValue *pointee = const_ptr_pointee(ira->codegen, comptime_value); |
| 13659 | if (!pointee) return ira->codegen->builtin_types.entry_invalid; |
| 13658 | 13660 | if (pointee->type == child_type) { |
| 13659 | 13661 | ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); |
| 13660 | 13662 | copy_const_val(out_val, pointee, value->value.data.x_ptr.mut == ConstPtrMutComptimeConst); |
| ... | ... | @@ -14058,6 +14060,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14058 | 14060 | ptr_type = ptr_type->data.pointer.child_type; |
| 14059 | 14061 | if (orig_array_ptr_val->special != ConstValSpecialRuntime) { |
| 14060 | 14062 | orig_array_ptr_val = const_ptr_pointee(ira->codegen, orig_array_ptr_val); |
| 14063 | if (!orig_array_ptr_val) return ira->codegen->builtin_types.entry_invalid; |
| 14061 | 14064 | } |
| 14062 | 14065 | } |
| 14063 | 14066 | if (array_type->data.array.len == 0) { |
| ... | ... | @@ -14099,6 +14102,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc |
| 14099 | 14102 | if (!ptr_val) |
| 14100 | 14103 | return ira->codegen->builtin_types.entry_invalid; |
| 14101 | 14104 | ConstExprValue *args_val = const_ptr_pointee(ira->codegen, ptr_val); |
| 14105 | if (!args_val) return ira->codegen->builtin_types.entry_invalid; |
| 14102 | 14106 | size_t start = args_val->data.x_arg_tuple.start_index; |
| 14103 | 14107 | size_t end = args_val->data.x_arg_tuple.end_index; |
| 14104 | 14108 | uint64_t elem_index_val; |
| ... | ... | @@ -14380,6 +14384,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14380 | 14384 | |
| 14381 | 14385 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 14382 | 14386 | ConstExprValue *struct_val = const_ptr_pointee(ira->codegen, ptr_val); |
| 14387 | if (!struct_val) return ira->codegen->invalid_instruction; |
| 14383 | 14388 | if (type_is_invalid(struct_val->type)) |
| 14384 | 14389 | return ira->codegen->invalid_instruction; |
| 14385 | 14390 | ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; |
| ... | ... | @@ -14422,6 +14427,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 14422 | 14427 | |
| 14423 | 14428 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 14424 | 14429 | ConstExprValue *union_val = const_ptr_pointee(ira->codegen, ptr_val); |
| 14430 | if (!union_val) return ira->codegen->invalid_instruction; |
| 14425 | 14431 | if (type_is_invalid(union_val->type)) |
| 14426 | 14432 | return ira->codegen->invalid_instruction; |
| 14427 | 14433 | |
| ... | ... | @@ -14618,6 +14624,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14618 | 14624 | |
| 14619 | 14625 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 14620 | 14626 | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 14627 | if (!child_val) return ira->codegen->builtin_types.entry_invalid; |
| 14621 | 14628 | |
| 14622 | 14629 | if (buf_eql_str(field_name, "len")) { |
| 14623 | 14630 | ConstExprValue *len_val = create_const_vals(1); |
| ... | ... | @@ -14642,6 +14649,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14642 | 14649 | |
| 14643 | 14650 | assert(container_ptr->value.type->id == TypeTableEntryIdPointer); |
| 14644 | 14651 | ConstExprValue *child_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 14652 | if (!child_val) return ira->codegen->builtin_types.entry_invalid; |
| 14645 | 14653 | TypeTableEntry *child_type = child_val->data.x_type; |
| 14646 | 14654 | |
| 14647 | 14655 | if (type_is_invalid(child_type)) { |
| ... | ... | @@ -14910,6 +14918,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru |
| 14910 | 14918 | return ira->codegen->builtin_types.entry_invalid; |
| 14911 | 14919 | |
| 14912 | 14920 | ConstExprValue *namespace_val = const_ptr_pointee(ira->codegen, container_ptr_val); |
| 14921 | if (!namespace_val) return ira->codegen->builtin_types.entry_invalid; |
| 14913 | 14922 | assert(namespace_val->special == ConstValSpecialStatic); |
| 14914 | 14923 | |
| 14915 | 14924 | ImportTableEntry *namespace_import = namespace_val->data.x_import; |
| ... | ... | @@ -14986,6 +14995,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 14986 | 14995 | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) { |
| 14987 | 14996 | if (instr_is_comptime(casted_value)) { |
| 14988 | 14997 | ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value); |
| 14998 | if (!dest_val) return ira->codegen->builtin_types.entry_invalid; |
| 14989 | 14999 | if (dest_val->special != ConstValSpecialRuntime) { |
| 14990 | 15000 | *dest_val = casted_value->value; |
| 14991 | 15001 | if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) { |
| ... | ... | @@ -14997,6 +15007,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru |
| 14997 | 15007 | ir_add_error(ira, &store_ptr_instruction->base, |
| 14998 | 15008 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 14999 | 15009 | ConstExprValue *dest_val = const_ptr_pointee(ira->codegen, &ptr->value); |
| 15010 | if (!dest_val) return ira->codegen->builtin_types.entry_invalid; |
| 15000 | 15011 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 15001 | 15012 | |
| 15002 | 15013 | return ira->codegen->builtin_types.entry_invalid; |
| ... | ... | @@ -15850,7 +15861,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 15850 | 15861 | ConstExprValue *pointee_val = nullptr; |
| 15851 | 15862 | if (instr_is_comptime(target_value_ptr)) { |
| 15852 | 15863 | pointee_val = const_ptr_pointee(ira->codegen, &target_value_ptr->value); |
| 15853 | | if (pointee_val->special == ConstValSpecialRuntime) |
| 15864 | if (pointee_val && pointee_val->special == ConstValSpecialRuntime) |
| 15854 | 15865 | pointee_val = nullptr; |
| 15855 | 15866 | } |
| 15856 | 15867 | if ((err = ensure_complete_type(ira->codegen, target_type))) |
| ... | ... | @@ -15981,6 +15992,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr |
| 15981 | 15992 | return ira->codegen->builtin_types.entry_invalid; |
| 15982 | 15993 | |
| 15983 | 15994 | ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, target_val_ptr); |
| 15995 | if (!pointee_val) return ira->codegen->builtin_types.entry_invalid; |
| 15984 | 15996 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| 15985 | 15997 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 15986 | 15998 | out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; |
| ... | ... | @@ -18732,11 +18744,14 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18732 | 18744 | TypeTableEntry *child_array_type = array_type->data.pointer.child_type; |
| 18733 | 18745 | assert(child_array_type->id == TypeTableEntryIdArray); |
| 18734 | 18746 | parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); |
| 18747 | if (!parent_ptr) return ira->codegen->builtin_types.entry_invalid; |
| 18735 | 18748 | array_val = const_ptr_pointee(ira->codegen, parent_ptr); |
| 18749 | if (!array_val) return ira->codegen->builtin_types.entry_invalid; |
| 18736 | 18750 | rel_end = child_array_type->data.array.len; |
| 18737 | 18751 | abs_offset = 0; |
| 18738 | 18752 | } else { |
| 18739 | 18753 | array_val = const_ptr_pointee(ira->codegen, &ptr_ptr->value); |
| 18754 | if (!array_val) return ira->codegen->builtin_types.entry_invalid; |
| 18740 | 18755 | rel_end = array_type->data.array.len; |
| 18741 | 18756 | parent_ptr = nullptr; |
| 18742 | 18757 | abs_offset = 0; |
| ... | ... | @@ -18744,6 +18759,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18744 | 18759 | } else if (array_type->id == TypeTableEntryIdPointer) { |
| 18745 | 18760 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 18746 | 18761 | parent_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); |
| 18762 | if (!parent_ptr) return ira->codegen->builtin_types.entry_invalid; |
| 18747 | 18763 | if (parent_ptr->special == ConstValSpecialUndef) { |
| 18748 | 18764 | array_val = nullptr; |
| 18749 | 18765 | abs_offset = 0; |
| ... | ... | @@ -18775,6 +18791,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio |
| 18775 | 18791 | } |
| 18776 | 18792 | } else if (is_slice(array_type)) { |
| 18777 | 18793 | ConstExprValue *slice_ptr = const_ptr_pointee(ira->codegen, &ptr_ptr->value); |
| 18794 | if (!slice_ptr) return ira->codegen->builtin_types.entry_invalid; |
| 18778 | 18795 | parent_ptr = &slice_ptr->data.x_struct.fields[slice_ptr_index]; |
| 18779 | 18796 | ConstExprValue *len_val = &slice_ptr->data.x_struct.fields[slice_len_index]; |
| 18780 | 18797 | |
| ... | ... | @@ -19175,6 +19192,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst |
| 19175 | 19192 | BigInt *op1_bigint = &casted_op1->value.data.x_bigint; |
| 19176 | 19193 | BigInt *op2_bigint = &casted_op2->value.data.x_bigint; |
| 19177 | 19194 | ConstExprValue *pointee_val = const_ptr_pointee(ira->codegen, &casted_result_ptr->value); |
| 19195 | if (!pointee_val) return ira->codegen->builtin_types.entry_invalid; |
| 19178 | 19196 | BigInt *dest_bigint = &pointee_val->data.x_bigint; |
| 19179 | 19197 | switch (instruction->op) { |
| 19180 | 19198 | case IrOverflowOpAdd: |
| ... | ... | @@ -19275,6 +19293,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 19275 | 19293 | if (!ptr_val) |
| 19276 | 19294 | return ira->codegen->builtin_types.entry_invalid; |
| 19277 | 19295 | ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val); |
| 19296 | if (!err_union_val) return ira->codegen->builtin_types.entry_invalid; |
| 19278 | 19297 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19279 | 19298 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19280 | 19299 | assert(err); |
| ... | ... | @@ -19323,6 +19342,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 19323 | 19342 | if (!ptr_val) |
| 19324 | 19343 | return ira->codegen->builtin_types.entry_invalid; |
| 19325 | 19344 | ConstExprValue *err_union_val = const_ptr_pointee(ira->codegen, ptr_val); |
| 19345 | if (!err_union_val) return ira->codegen->builtin_types.entry_invalid; |
| 19326 | 19346 | if (err_union_val->special != ConstValSpecialRuntime) { |
| 19327 | 19347 | ErrorTableEntry *err = err_union_val->data.x_err_union.err; |
| 19328 | 19348 | if (err != nullptr) { |