authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-17 21:39:59-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-17 21:55:14-04:00
loge5a0414b05134bfebba4fba097ae882ee0cf36cf
treeacac42272d6be5fbd3d27c9ab6efcce817efc86a
parent4e182c7e9e44a97fe925344057b7b30c3ff2cae4
signaturelock-open Commit is signed but in an unrecognized format.

misc fixes


2 files changed, 124 insertions(+), 85 deletions(-)

src/all_types.hpp+1-1
......@@ -2544,8 +2544,8 @@ struct IrInstructionElemPtr {
25442544
25452545 IrInstruction *array_ptr;
25462546 IrInstruction *elem_index;
2547 IrInstruction *init_array_type;
25472548 PtrLen ptr_len;
2548 bool initializing;
25492549 bool safety_check_on;
25502550};
25512551
src/ir.cpp+123-84
......@@ -189,7 +189,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
189189static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
190190 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value);
191191static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
192 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value);
192 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime);
193193static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,
194194 IrInstruction *base_ptr, bool safety_check_on, bool initializing);
195195static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,
......@@ -261,6 +261,15 @@ static bool is_opt_err_set(ZigType *ty) {
261261 (ty->id == ZigTypeIdOptional && ty->data.maybe.child_type->id == ZigTypeIdErrorSet);
262262}
263263
264static bool is_slice(ZigType *type) {
265 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
266}
267
268static bool slice_is_const(ZigType *type) {
269 assert(is_slice(type));
270 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
271}
272
264273// This function returns true when you can change the type of a ConstExprValue and the
265274// value remains meaningful.
266275static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
......@@ -297,8 +306,9 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) {
297306 return a->data.floating.bit_count == b->data.floating.bit_count;
298307 case ZigTypeIdInt:
299308 return a->data.integral.is_signed == b->data.integral.is_signed;
300 case ZigTypeIdArray:
301309 case ZigTypeIdStruct:
310 return is_slice(a) && is_slice(b);
311 case ZigTypeIdArray:
302312 case ZigTypeIdOptional:
303313 case ZigTypeIdErrorUnion:
304314 case ZigTypeIdEnum:
......@@ -1317,17 +1327,18 @@ static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_
13171327
13181328static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
13191329 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,
1320 bool initializing)
1330 IrInstruction *init_array_type)
13211331{
13221332 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);
13231333 instruction->array_ptr = array_ptr;
13241334 instruction->elem_index = elem_index;
13251335 instruction->safety_check_on = safety_check_on;
13261336 instruction->ptr_len = ptr_len;
1327 instruction->initializing = initializing;
1337 instruction->init_array_type = init_array_type;
13281338
13291339 ir_ref_instruction(array_ptr, irb->current_basic_block);
13301340 ir_ref_instruction(elem_index, irb->current_basic_block);
1341 if (init_array_type != nullptr) ir_ref_instruction(init_array_type, irb->current_basic_block);
13311342
13321343 return &instruction->base;
13331344}
......@@ -4269,7 +4280,7 @@ static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode
42694280 return subscript_instruction;
42704281
42714282 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
4272 subscript_instruction, true, PtrLenSingle, false);
4283 subscript_instruction, true, PtrLenSingle, nullptr);
42734284 if (lval == LValPtr)
42744285 return ptr_instruction;
42754286
......@@ -5809,7 +5820,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
58095820
58105821 IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
58115822 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr, elem_index,
5812 false, PtrLenSingle, true);
5823 false, PtrLenSingle, container_type);
58135824 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
58145825 result_loc_inst->base.id = ResultLocIdInstruction;
58155826 result_loc_inst->base.source_instruction = elem_ptr;
......@@ -6313,7 +6324,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
63136324
63146325 ir_set_cursor_at_end_and_append_block(irb, body_block);
63156326 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false,
6316 PtrLenSingle, false);
6327 PtrLenSingle, nullptr);
63176328 // TODO make it an error to write to element variable or i variable.
63186329 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
63196330 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
......@@ -9614,15 +9625,6 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
96149625 return false;
96159626}
96169627
9617static bool is_slice(ZigType *type) {
9618 return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
9619}
9620
9621static bool slice_is_const(ZigType *type) {
9622 assert(is_slice(type));
9623 return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const;
9624}
9625
96269628static bool is_tagged_union(ZigType *type) {
96279629 if (type->id != ZigTypeIdUnion)
96289630 return false;
......@@ -10831,7 +10833,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
1083110833 }
1083210834
1083310835 if (result_loc == nullptr) result_loc = no_result_loc();
10834 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr);
10836 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
1083510837 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1083610838 return result_loc_inst;
1083710839 }
......@@ -11265,7 +11267,7 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
1126511267 }
1126611268
1126711269 if (result_loc == nullptr) result_loc = no_result_loc();
11268 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr);
11270 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
1126911271 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1127011272 return result_loc_inst;
1127111273 }
......@@ -11307,7 +11309,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
1130711309 IrInstruction *result_loc_inst;
1130811310 if (handle_is_ptr(wanted_type)) {
1130911311 if (result_loc == nullptr) result_loc = no_result_loc();
11310 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr);
11312 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
1131111313 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1131211314 return result_loc_inst;
1131311315 }
......@@ -11392,7 +11394,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
1139211394 IrInstruction *result_loc_inst;
1139311395 if (handle_is_ptr(wanted_type)) {
1139411396 if (result_loc == nullptr) result_loc = no_result_loc();
11395 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr);
11397 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
1139611398 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1139711399 return result_loc_inst;
1139811400 }
......@@ -11465,7 +11467,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi
1146511467
1146611468 IrInstruction *result_loc;
1146711469 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) {
11468 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr);
11470 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true);
1146911471 } else {
1147011472 result_loc = nullptr;
1147111473 }
......@@ -11509,7 +11511,7 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s
1150911511 if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false);
1151011512
1151111513 if (result_loc == nullptr) result_loc = no_result_loc();
11512 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr);
11514 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
1151311515 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1151411516 return result_loc_inst;
1151511517 }
......@@ -12162,7 +12164,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
1216212164 result->value.type = array_type;
1216312165 return result;
1216412166 }
12165 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr);
12167 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true);
1216612168 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1216712169 return result_loc_inst;
1216812170 }
......@@ -12743,7 +12745,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
1274312745 IrInstruction *result_loc_inst;
1274412746 if (type_entry->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {
1274512747 if (result_loc == nullptr) result_loc = no_result_loc();
12746 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr);
12748 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true);
1274712749 if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
1274812750 return result_loc_inst;
1274912751 }
......@@ -14923,7 +14925,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1492314925 return ira->codegen->invalid_instruction;
1492414926 }
1492514927 IrInstruction *alloca_gen;
14926 if (is_comptime) {
14928 if (is_comptime && value != nullptr) {
1492714929 if (align > value->value.global_refs->align) {
1492814930 value->value.global_refs->align = align;
1492914931 }
......@@ -14978,12 +14980,14 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1497814980 }
1497914981
1498014982 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
14981 peer_parent->resolved_type, nullptr);
14983 peer_parent->resolved_type, nullptr, false);
1498214984 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
1498314985 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
1498414986 {
1498514987 return parent_result_loc;
1498614988 }
14989 // because is_comptime is false, we mark this a runtime pointer
14990 parent_result_loc->value.data.x_ptr.mut = ConstPtrMutRuntimeVar;
1498714991 result_loc->written = true;
1498814992 result_loc->resolved_loc = parent_result_loc;
1498914993 return result_loc->resolved_loc;
......@@ -15026,7 +15030,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1502615030 }
1502715031
1502815032 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
15029 dest_type, bitcasted_value);
15033 dest_type, bitcasted_value, false);
1503015034 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) ||
1503115035 parent_result_loc->value.type->id == ZigTypeIdUnreachable)
1503215036 {
......@@ -15054,12 +15058,17 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1505415058}
1505515059
1505615060static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,
15057 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value)
15061 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime)
1505815062{
1505915063 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
1506015064 value);
1506115065 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type)))
1506215066 return result_loc;
15067
15068 if (force_runtime && result_loc_pass1->written && result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {
15069 result_loc->value.special = ConstValSpecialRuntime;
15070 }
15071
1506315072 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr);
1506415073 ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type;
1506515074 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
......@@ -15099,10 +15108,20 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrIn
1509915108 ZigType *implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
1510015109 if (type_is_invalid(implicit_elem_type))
1510115110 return ira->codegen->invalid_instruction;
15102 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, implicit_elem_type, nullptr);
15103 if (result_loc != nullptr)
15104 return result_loc;
15105 zig_panic("TODO");
15111 ResultLoc *old_result_loc = instruction->result_loc;
15112 for (;;) {
15113 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, old_result_loc,
15114 implicit_elem_type, nullptr, false);
15115 if (result_loc != nullptr)
15116 return result_loc;
15117
15118 if (instruction->result_loc->id == ResultLocIdPeer) {
15119 old_result_loc = reinterpret_cast<ResultLocPeer *>(instruction->result_loc)->parent->parent;
15120 continue;
15121 }
15122 ir_assert(false, &instruction->base); // TODO
15123 zig_unreachable();
15124 }
1510615125}
1510715126
1510815127static void ir_reset_result(ResultLoc *result_loc) {
......@@ -15484,13 +15503,6 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1548415503 return result;
1548515504}
1548615505
15487static void mark_inferred_ptr_runtime(IrInstruction *ptr) {
15488 ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr);
15489 if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) {
15490 ptr->value.special = ConstValSpecialRuntime;
15491 }
15492}
15493
1549415506static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction,
1549515507 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,
1549615508 IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline)
......@@ -15931,11 +15943,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1593115943 IrInstruction *result_loc;
1593215944 if (handle_is_ptr(impl_fn_type_id->return_type)) {
1593315945 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
15934 impl_fn_type_id->return_type, nullptr);
15946 impl_fn_type_id->return_type, nullptr, true);
1593515947 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
1593615948 return result_loc;
1593715949 }
15938 mark_inferred_ptr_runtime(result_loc);
1593915950 } else {
1594015951 result_loc = nullptr;
1594115952 }
......@@ -16052,11 +16063,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1605216063 IrInstruction *result_loc;
1605316064 if (handle_is_ptr(return_type)) {
1605416065 result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc,
16055 return_type, nullptr);
16066 return_type, nullptr, true);
1605616067 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
1605716068 return result_loc;
1605816069 }
16059 mark_inferred_ptr_runtime(result_loc);
1606016070 } else {
1606116071 result_loc = nullptr;
1606216072 }
......@@ -16547,7 +16557,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1654716557
1654816558 // In case resolving the parent activates a suspend, do it now
1654916559 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,
16550 peer_parent->resolved_type, nullptr);
16560 peer_parent->resolved_type, nullptr, false);
1655116561 if (parent_result_loc != nullptr &&
1655216562 (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc)))
1655316563 {
......@@ -16893,19 +16903,45 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1689316903 if (array_ptr_val == nullptr)
1689416904 return ira->codegen->invalid_instruction;
1689516905
16896 if (array_ptr_val->special == ConstValSpecialUndef && array_type->id == ZigTypeIdArray &&
16897 elem_ptr_instruction->initializing)
16898 {
16899 array_ptr_val->data.x_array.special = ConstArraySpecialNone;
16900 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
16901 array_ptr_val->special = ConstValSpecialStatic;
16902 for (size_t i = 0; i < array_type->data.array.len; i += 1) {
16903 ConstExprValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];
16904 elem_val->special = ConstValSpecialUndef;
16905 elem_val->type = array_type->data.array.child_type;
16906 elem_val->parent.id = ConstParentIdArray;
16907 elem_val->parent.data.p_array.array_val = array_ptr_val;
16908 elem_val->parent.data.p_array.elem_index = i;
16906 if (array_ptr_val->special == ConstValSpecialUndef && elem_ptr_instruction->init_array_type != nullptr) {
16907 if (array_type->id == ZigTypeIdArray) {
16908 array_ptr_val->data.x_array.special = ConstArraySpecialNone;
16909 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
16910 array_ptr_val->special = ConstValSpecialStatic;
16911 for (size_t i = 0; i < array_type->data.array.len; i += 1) {
16912 ConstExprValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];
16913 elem_val->special = ConstValSpecialUndef;
16914 elem_val->type = array_type->data.array.child_type;
16915 elem_val->parent.id = ConstParentIdArray;
16916 elem_val->parent.data.p_array.array_val = array_ptr_val;
16917 elem_val->parent.data.p_array.elem_index = i;
16918 }
16919 } else if (is_slice(array_type)) {
16920 ZigType *actual_array_type = ir_resolve_type(ira, elem_ptr_instruction->init_array_type->child);
16921 if (type_is_invalid(actual_array_type))
16922 return ira->codegen->invalid_instruction;
16923 assert(actual_array_type->id == ZigTypeIdArray);
16924
16925 ConstExprValue *array_init_val = create_const_vals(1);
16926 array_init_val->special = ConstValSpecialStatic;
16927 array_init_val->type = actual_array_type;
16928 array_init_val->data.x_array.special = ConstArraySpecialNone;
16929 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);
16930 array_init_val->special = ConstValSpecialStatic;
16931 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {
16932 ConstExprValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];
16933 elem_val->special = ConstValSpecialUndef;
16934 elem_val->type = actual_array_type->data.array.child_type;
16935 elem_val->parent.id = ConstParentIdArray;
16936 elem_val->parent.data.p_array.array_val = array_init_val;
16937 elem_val->parent.data.p_array.elem_index = i;
16938 }
16939
16940 init_const_slice(ira->codegen, array_ptr_val, array_init_val, 0, actual_array_type->data.array.len,
16941 false);
16942 array_ptr_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.mut = ConstPtrMutInfer;
16943 } else {
16944 zig_unreachable();
1690916945 }
1691016946 }
1691116947
......@@ -16976,7 +17012,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1697617012 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
1697717013 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1697817014 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
16979 elem_ptr_instruction->ptr_len, false);
17015 elem_ptr_instruction->ptr_len, nullptr);
1698017016 result->value.type = return_type;
1698117017 return result;
1698217018 }
......@@ -17033,7 +17069,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1703317069 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
1703417070 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1703517071 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,
17036 false, elem_ptr_instruction->ptr_len, elem_ptr_instruction->initializing);
17072 false, elem_ptr_instruction->ptr_len, elem_ptr_instruction->init_array_type);
1703717073 result->value.type = return_type;
1703817074 result->value.special = ConstValSpecialStatic;
1703917075 } else {
......@@ -17077,7 +17113,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1707717113
1707817114 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1707917115 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,
17080 elem_ptr_instruction->ptr_len, elem_ptr_instruction->initializing);
17116 elem_ptr_instruction->ptr_len, elem_ptr_instruction->init_array_type);
1708117117 result->value.type = return_type;
1708217118 return result;
1708317119}
......@@ -18963,7 +18999,7 @@ static IrInstruction *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrI
1896318999 if (instr_is_comptime(field_result_loc) &&
1896419000 field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar)
1896519001 {
18966 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
19002 // nothing
1896719003 } else {
1896819004 result_loc->value.special = ConstValSpecialRuntime;
1896919005 }
......@@ -19099,9 +19135,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
1909919135 return ira->codegen->invalid_instruction;
1910019136
1910119137 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {
19102 if (const_ptrs.length == actual_field_count) {
19103 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
19104 } else {
19138 if (const_ptrs.length != actual_field_count) {
1910519139 result_loc->value.special = ConstValSpecialRuntime;
1910619140 for (size_t i = 0; i < const_ptrs.length; i += 1) {
1910719141 IrInstruction *field_result_loc = const_ptrs.at(i);
......@@ -19218,9 +19252,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
1921819252 }
1921919253
1922019254 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {
19221 if (const_ptrs.length == elem_count) {
19222 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
19223 } else {
19255 if (const_ptrs.length != elem_count) {
1922419256 result_loc->value.special = ConstValSpecialRuntime;
1922519257 for (size_t i = 0; i < const_ptrs.length; i += 1) {
1922619258 IrInstruction *elem_result_loc = const_ptrs.at(i);
......@@ -20884,18 +20916,6 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2088420916 if (type_is_invalid(ptr->value.type))
2088520917 return ira->codegen->invalid_instruction;
2088620918
20887 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
20888 IrInstruction *result_loc;
20889 if (handle_is_ptr(result_type)) {
20890 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
20891 result_type, nullptr);
20892 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
20893 return result_loc;
20894 }
20895 } else {
20896 result_loc = nullptr;
20897 }
20898
2089920919 // TODO let this be volatile
2090020920 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
2090120921 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);
......@@ -20959,6 +20979,18 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
2095920979 zig_panic("TODO compile-time execution of cmpxchg");
2096020980 }
2096120981
20982 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
20983 IrInstruction *result_loc;
20984 if (handle_is_ptr(result_type)) {
20985 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
20986 result_type, nullptr, true);
20987 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
20988 return result_loc;
20989 }
20990 } else {
20991 result_loc = nullptr;
20992 }
20993
2096220994 return ir_build_cmpxchg_gen(ira, &instruction->base, result_type,
2096320995 casted_ptr, casted_cmp_value, casted_new_value,
2096420996 success_order, failure_order, instruction->is_weak, result_loc);
......@@ -21208,7 +21240,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2120821240 }
2120921241
2121021242 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
21211 dest_slice_type, nullptr);
21243 dest_slice_type, nullptr, true);
2121221244 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2121321245 return result_loc;
2121421246 }
......@@ -21285,7 +21317,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
2128521317 }
2128621318
2128721319 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
21288 dest_slice_type, nullptr);
21320 dest_slice_type, nullptr, true);
2128921321 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2129021322 return result_loc;
2129121323 }
......@@ -22027,7 +22059,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2202722059 }
2202822060
2202922061 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
22030 return_type, nullptr);
22062 return_type, nullptr, true);
2203122063 if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) {
2203222064 return result_loc;
2203322065 }
......@@ -24461,7 +24493,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2446124493 bool want_resolve_result = !instruction->result_loc->written;
2446224494 if (want_resolve_result) {
2446324495 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,
24464 value->value.type, value);
24496 value->value.type, value, false);
2446524497 if (result_loc != nullptr) {
2446624498 if (type_is_invalid(result_loc->value.type))
2446724499 return ira->codegen->invalid_instruction;
......@@ -24470,6 +24502,13 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2447024502
2447124503 instruction->result_loc->written = true;
2447224504 ir_analyze_store_ptr(ira, &instruction->base, result_loc, value);
24505 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {
24506 if (instr_is_comptime(value)) {
24507 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
24508 } else {
24509 result_loc->value.special = ConstValSpecialRuntime;
24510 }
24511 }
2447324512 }
2447424513 }
2447524514
......@@ -24482,7 +24521,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInst
2448224521 return operand;
2448324522
2448424523 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
24485 &instruction->result_loc_bit_cast->base, operand->value.type, operand);
24524 &instruction->result_loc_bit_cast->base, operand->value.type, operand, false);
2448624525 if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)))
2448724526 return result_loc;
2448824527