authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-09 10:44:57-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-09 10:44:57-05:00
log3b2eeb839bb34903596edeae041b5d9ab189282d
tree05c4b419771e26ed502e282d2ad4594e52f938cb
parent027a0c46aef9828ab07d6342030c1ba5b5e4f769
parent5864d92b4049e6d60a21a3f22220464808dd0518

Merge remote-tracking branch 'origin/master' into llvm8


5 files changed, 102 insertions(+), 60 deletions(-)

src/analyze.cpp+19-2
...@@ -5757,7 +5757,8 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy...@@ -5757,7 +5757,8 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy
5757 case ConstPtrSpecialRef:5757 case ConstPtrSpecialRef:
5758 case ConstPtrSpecialBaseStruct:5758 case ConstPtrSpecialBaseStruct:
5759 buf_appendf(buf, "*");5759 buf_appendf(buf, "*");
5760 render_const_value(g, buf, const_ptr_pointee(g, const_val));5760 // TODO we need a source node for const_ptr_pointee because it can generate compile errors
5761 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
5761 return;5762 return;
5762 case ConstPtrSpecialBaseArray:5763 case ConstPtrSpecialBaseArray:
5763 if (const_val->data.x_ptr.data.base_array.is_cstr) {5764 if (const_val->data.x_ptr.data.base_array.is_cstr) {
...@@ -5765,7 +5766,8 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy...@@ -5765,7 +5766,8 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy
5765 return;5766 return;
5766 } else {5767 } else {
5767 buf_appendf(buf, "*");5768 buf_appendf(buf, "*");
5768 render_const_value(g, buf, const_ptr_pointee(g, const_val));5769 // TODO we need a source node for const_ptr_pointee because it can generate compile errors
5770 render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
5769 return;5771 return;
5770 }5772 }
5771 case ConstPtrSpecialHardCodedAddr:5773 case ConstPtrSpecialHardCodedAddr:
...@@ -6599,3 +6601,18 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f...@@ -6599,3 +6601,18 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f
6599 LLVMTypeRef field_type = LLVMStructGetTypeAtIndex(struct_type->type_ref, field->gen_index);6601 LLVMTypeRef field_type = LLVMStructGetTypeAtIndex(struct_type->type_ref, field->gen_index);
6600 return LLVMStoreSizeOfType(g->target_data_ref, field_type);6602 return LLVMStoreSizeOfType(g->target_data_ref, field_type);
6601}6603}
6604
6605Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
6606 ConstExprValue *const_val, ZigType *wanted_type)
6607{
6608 ConstExprValue ptr_val = {};
6609 ptr_val.special = ConstValSpecialStatic;
6610 ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);
6611 ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;
6612 ptr_val.data.x_ptr.special = ConstPtrSpecialRef;
6613 ptr_val.data.x_ptr.data.ref.pointee = const_val;
6614 if (const_ptr_pointee(ira, codegen, &ptr_val, source_node) == nullptr)
6615 return ErrorSemanticAnalyzeFail;
6616
6617 return ErrorNone;
6618}
src/analyze.hpp+3
...@@ -222,4 +222,7 @@ enum ReqCompTime {...@@ -222,4 +222,7 @@ enum ReqCompTime {
222};222};
223ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);223ReqCompTime type_requires_comptime(CodeGen *g, ZigType *type_entry);
224224
225Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
226 ConstExprValue *const_val, ZigType *wanted_type);
227
225#endif228#endif
src/codegen.cpp+8
...@@ -5626,6 +5626,8 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con...@@ -5626,6 +5626,8 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con
5626}5626}
56275627
5628static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {5628static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) {
5629 Error err;
5630
5629 ZigType *type_entry = const_val->type;5631 ZigType *type_entry = const_val->type;
5630 assert(!type_entry->zero_bits);5632 assert(!type_entry->zero_bits);
56315633
...@@ -5769,6 +5771,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c...@@ -5769,6 +5771,12 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
5769 }5771 }
5770 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];5772 ConstExprValue *field_val = &const_val->data.x_struct.fields[i];
5771 assert(field_val->type != nullptr);5773 assert(field_val->type != nullptr);
5774 if ((err = ensure_const_val_repr(nullptr, g, nullptr, field_val,
5775 type_struct_field->type_entry)))
5776 {
5777 zig_unreachable();
5778 }
5779
5772 LLVMValueRef val = gen_const_val(g, field_val, "");5780 LLVMValueRef val = gen_const_val(g, field_val, "");
5773 fields[type_struct_field->gen_index] = val;5781 fields[type_struct_field->gen_index] = val;
5774 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(field_val->type, val);5782 make_unnamed_struct = make_unnamed_struct || is_llvm_value_unnamed_type(field_val->type, val);
src/ir.cpp+68-57
...@@ -159,9 +159,9 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op...@@ -159,9 +159,9 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
159static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);159static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval);
160static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);160static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
161static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);161static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
162static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t *buf, ConstExprValue *val);162static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val);
163static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);163static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val);
164static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,164static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
165 ConstExprValue *out_val, ConstExprValue *ptr_val);165 ConstExprValue *out_val, ConstExprValue *ptr_val);
166static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,166static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,
167 ZigType *dest_type, IrInstruction *dest_type_src);167 ZigType *dest_type, IrInstruction *dest_type_src);
...@@ -7391,35 +7391,46 @@ static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *ms...@@ -7391,35 +7391,46 @@ static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *ms
7391 return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg);7391 return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg);
7392}7392}
73937393
7394static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {
7395 if (ira != nullptr)
7396 return exec_add_error_node(codegen, ira->new_irb.exec, source_node, msg);
7397 else
7398 return add_node_error(codegen, source_node, msg);
7399}
7400
7394static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {7401static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {
7395 return ir_add_error_node(ira, source_instruction->source_node, msg);7402 return ir_add_error_node(ira, source_instruction->source_node, msg);
7396}7403}
73977404
7398// This function takes a comptime ptr and makes the child const value conform to the type7405// This function takes a comptime ptr and makes the child const value conform to the type
7399// described by the pointer.7406// described by the pointer.
7400static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, AstNode *source_node, ConstExprValue *ptr_val) {7407static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
7408 ConstExprValue *ptr_val)
7409{
7401 Error err;7410 Error err;
7402 assert(ptr_val->type->id == ZigTypeIdPointer);7411 assert(ptr_val->type->id == ZigTypeIdPointer);
7403 ConstExprValue tmp = {};7412 ConstExprValue tmp = {};
7404 tmp.special = ConstValSpecialStatic;7413 tmp.special = ConstValSpecialStatic;
7405 tmp.type = ptr_val->type->data.pointer.child_type;7414 tmp.type = ptr_val->type->data.pointer.child_type;
7406 if ((err = ir_read_const_ptr(ira, source_node, &tmp, ptr_val)))7415 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
7407 return err;7416 return err;
7408 ConstExprValue *child_val = const_ptr_pointee_unchecked(ira->codegen, ptr_val);7417 ConstExprValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
7409 copy_const_val(child_val, &tmp, false);7418 copy_const_val(child_val, &tmp, false);
7410 return ErrorNone;7419 return ErrorNone;
7411}7420}
74127421
7413static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) {7422ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,
7423 AstNode *source_node)
7424{
7414 Error err;7425 Error err;
7415 ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val);7426 ConstExprValue *val = const_ptr_pointee_unchecked(codegen, const_val);
7416 assert(val != nullptr);7427 assert(val != nullptr);
7417 assert(const_val->type->id == ZigTypeIdPointer);7428 assert(const_val->type->id == ZigTypeIdPointer);
7418 ZigType *expected_type = const_val->type->data.pointer.child_type;7429 ZigType *expected_type = const_val->type->data.pointer.child_type;
7419 if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {7430 if (!types_have_same_zig_comptime_repr(val->type, expected_type)) {
7420 if ((err = eval_comptime_ptr_reinterpret(ira, source_node, const_val)))7431 if ((err = eval_comptime_ptr_reinterpret(ira, codegen, source_node, const_val)))
7421 return nullptr;7432 return nullptr;
7422 return const_ptr_pointee_unchecked(ira->codegen, const_val);7433 return const_ptr_pointee_unchecked(codegen, const_val);
7423 }7434 }
7424 return val;7435 return val;
7425}7436}
...@@ -9461,7 +9472,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -9461,7 +9472,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
9461 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));9472 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));
94629473
9463 if (instr_is_comptime(value)) {9474 if (instr_is_comptime(value)) {
9464 ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node);9475 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);
9465 if (pointee == nullptr)9476 if (pointee == nullptr)
9466 return ira->codegen->invalid_instruction;9477 return ira->codegen->invalid_instruction;
9467 if (pointee->special != ConstValSpecialRuntime) {9478 if (pointee->special != ConstValSpecialRuntime) {
...@@ -9497,7 +9508,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc...@@ -9497,7 +9508,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc
9497 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));9508 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type));
94989509
9499 if (instr_is_comptime(value)) {9510 if (instr_is_comptime(value)) {
9500 ConstExprValue *pointee = ir_const_ptr_pointee(ira, &value->value, source_instr->source_node);9511 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node);
9501 if (pointee == nullptr)9512 if (pointee == nullptr)
9502 return ira->codegen->invalid_instruction;9513 return ira->codegen->invalid_instruction;
9503 if (pointee->special != ConstValSpecialRuntime) {9514 if (pointee->special != ConstValSpecialRuntime) {
...@@ -10456,7 +10467,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -10456,7 +10467,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
10456 return ira->codegen->invalid_instruction;10467 return ira->codegen->invalid_instruction;
1045710468
10458 assert(val->type->id == ZigTypeIdPointer);10469 assert(val->type->id == ZigTypeIdPointer);
10459 ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node);10470 ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
10460 if (pointee == nullptr)10471 if (pointee == nullptr)
10461 return ira->codegen->invalid_instruction;10472 return ira->codegen->invalid_instruction;
10462 if (pointee->special != ConstValSpecialRuntime) {10473 if (pointee->special != ConstValSpecialRuntime) {
...@@ -11025,7 +11036,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -11025,7 +11036,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
11025 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,11036 IrInstruction *result = ir_create_const(&ira->new_irb, source_instruction->scope,
11026 source_instruction->source_node, child_type);11037 source_instruction->source_node, child_type);
1102711038
11028 if ((err = ir_read_const_ptr(ira, source_instruction->source_node, &result->value,11039 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, &result->value,
11029 &ptr->value)))11040 &ptr->value)))
11030 {11041 {
11031 return ira->codegen->invalid_instruction;11042 return ira->codegen->invalid_instruction;
...@@ -13730,21 +13741,21 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC...@@ -13730,21 +13741,21 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC
1373013741
13731// out_val->type must be the type to read the pointer as13742// out_val->type must be the type to read the pointer as
13732// if the type is different than the actual type then it does a comptime byte reinterpretation13743// if the type is different than the actual type then it does a comptime byte reinterpretation
13733static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,13744static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
13734 ConstExprValue *out_val, ConstExprValue *ptr_val)13745 ConstExprValue *out_val, ConstExprValue *ptr_val)
13735{13746{
13736 Error err;13747 Error err;
13737 assert(out_val->type != nullptr);13748 assert(out_val->type != nullptr);
1373813749
13739 ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr_val);13750 ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val);
1374013751
13741 if ((err = type_resolve(ira->codegen, pointee->type, ResolveStatusSizeKnown)))13752 if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown)))
13742 return ErrorSemanticAnalyzeFail;13753 return ErrorSemanticAnalyzeFail;
13743 if ((err = type_resolve(ira->codegen, out_val->type, ResolveStatusSizeKnown)))13754 if ((err = type_resolve(codegen, out_val->type, ResolveStatusSizeKnown)))
13744 return ErrorSemanticAnalyzeFail;13755 return ErrorSemanticAnalyzeFail;
1374513756
13746 size_t src_size = type_size(ira->codegen, pointee->type);13757 size_t src_size = type_size(codegen, pointee->type);
13747 size_t dst_size = type_size(ira->codegen, out_val->type);13758 size_t dst_size = type_size(codegen, out_val->type);
1374813759
13749 if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) {13760 if (src_size == dst_size && types_have_same_zig_comptime_repr(pointee->type, out_val->type)) {
13750 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst);13761 copy_const_val(out_val, pointee, ptr_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
...@@ -13754,8 +13765,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,...@@ -13754,8 +13765,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,
13754 if (dst_size <= src_size) {13765 if (dst_size <= src_size) {
13755 Buf buf = BUF_INIT;13766 Buf buf = BUF_INIT;
13756 buf_resize(&buf, src_size);13767 buf_resize(&buf, src_size);
13757 buf_write_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf), pointee);13768 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf), pointee);
13758 if ((err = buf_read_value_bytes(ira, source_node, (uint8_t*)buf_ptr(&buf), out_val)))13769 if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val)))
13759 return err;13770 return err;
13760 return ErrorNone;13771 return ErrorNone;
13761 }13772 }
...@@ -13764,7 +13775,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,...@@ -13764,7 +13775,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,
13764 case ConstPtrSpecialInvalid:13775 case ConstPtrSpecialInvalid:
13765 zig_unreachable();13776 zig_unreachable();
13766 case ConstPtrSpecialRef: {13777 case ConstPtrSpecialRef: {
13767 ir_add_error_node(ira, source_node,13778 opt_ir_add_error_node(ira, codegen, source_node,
13768 buf_sprintf("attempt to read %zu bytes from pointer to %s which is %zu bytes",13779 buf_sprintf("attempt to read %zu bytes from pointer to %s which is %zu bytes",
13769 dst_size, buf_ptr(&pointee->type->name), src_size));13780 dst_size, buf_ptr(&pointee->type->name), src_size));
13770 return ErrorSemanticAnalyzeFail;13781 return ErrorSemanticAnalyzeFail;
...@@ -13778,7 +13789,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,...@@ -13778,7 +13789,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,
13778 size_t elem_index = ptr_val->data.x_ptr.data.base_array.elem_index;13789 size_t elem_index = ptr_val->data.x_ptr.data.base_array.elem_index;
13779 src_size = elem_size * (array_val->type->data.array.len - elem_index);13790 src_size = elem_size * (array_val->type->data.array.len - elem_index);
13780 if (dst_size > src_size) {13791 if (dst_size > src_size) {
13781 ir_add_error_node(ira, source_node,13792 opt_ir_add_error_node(ira, codegen, source_node,
13782 buf_sprintf("attempt to read %zu bytes from %s at index %" ZIG_PRI_usize " which is %zu bytes",13793 buf_sprintf("attempt to read %zu bytes from %s at index %" ZIG_PRI_usize " which is %zu bytes",
13783 dst_size, buf_ptr(&array_val->type->name), elem_index, src_size));13794 dst_size, buf_ptr(&array_val->type->name), elem_index, src_size));
13784 return ErrorSemanticAnalyzeFail;13795 return ErrorSemanticAnalyzeFail;
...@@ -13788,9 +13799,9 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,...@@ -13788,9 +13799,9 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node,
13788 buf_resize(&buf, elem_count * elem_size);13799 buf_resize(&buf, elem_count * elem_size);
13789 for (size_t i = 0; i < elem_count; i += 1) {13800 for (size_t i = 0; i < elem_count; i += 1) {
13790 ConstExprValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i];13801 ConstExprValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i];
13791 buf_write_value_bytes(ira->codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);13802 buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val);
13792 }13803 }
13793 if ((err = buf_read_value_bytes(ira, source_node, (uint8_t*)buf_ptr(&buf), out_val)))13804 if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val)))
13794 return err;13805 return err;
13795 return ErrorNone;13806 return ErrorNone;
13796 }13807 }
...@@ -14227,7 +14238,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -14227,7 +14238,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
14227 array_type = array_type->data.pointer.child_type;14238 array_type = array_type->data.pointer.child_type;
14228 ptr_type = ptr_type->data.pointer.child_type;14239 ptr_type = ptr_type->data.pointer.child_type;
14229 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {14240 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
14230 orig_array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,14241 orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
14231 elem_ptr_instruction->base.source_node);14242 elem_ptr_instruction->base.source_node);
14232 if (orig_array_ptr_val == nullptr)14243 if (orig_array_ptr_val == nullptr)
14233 return ira->codegen->invalid_instruction;14244 return ira->codegen->invalid_instruction;
...@@ -14271,7 +14282,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -14271,7 +14282,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
14271 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);14282 ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
14272 if (!ptr_val)14283 if (!ptr_val)
14273 return ira->codegen->invalid_instruction;14284 return ira->codegen->invalid_instruction;
14274 ConstExprValue *args_val = ir_const_ptr_pointee(ira, ptr_val, elem_ptr_instruction->base.source_node);14285 ConstExprValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node);
14275 if (args_val == nullptr)14286 if (args_val == nullptr)
14276 return ira->codegen->invalid_instruction;14287 return ira->codegen->invalid_instruction;
14277 size_t start = args_val->data.x_arg_tuple.start_index;14288 size_t start = args_val->data.x_arg_tuple.start_index;
...@@ -14353,7 +14364,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -14353,7 +14364,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
14353 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||14364 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||
14354 array_type->id == ZigTypeIdArray))14365 array_type->id == ZigTypeIdArray))
14355 {14366 {
14356 ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val,14367 ConstExprValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
14357 elem_ptr_instruction->base.source_node);14368 elem_ptr_instruction->base.source_node);
14358 if (array_ptr_val == nullptr)14369 if (array_ptr_val == nullptr)
14359 return ira->codegen->invalid_instruction;14370 return ira->codegen->invalid_instruction;
...@@ -14572,7 +14583,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14572,7 +14583,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14572 return ira->codegen->invalid_instruction;14583 return ira->codegen->invalid_instruction;
1457314584
14574 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {14585 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14575 ConstExprValue *struct_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node);14586 ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
14576 if (struct_val == nullptr)14587 if (struct_val == nullptr)
14577 return ira->codegen->invalid_instruction;14588 return ira->codegen->invalid_instruction;
14578 if (type_is_invalid(struct_val->type))14589 if (type_is_invalid(struct_val->type))
...@@ -14614,7 +14625,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -14614,7 +14625,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
14614 return ira->codegen->invalid_instruction;14625 return ira->codegen->invalid_instruction;
1461514626
14616 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {14627 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
14617 ConstExprValue *union_val = ir_const_ptr_pointee(ira, ptr_val, source_instr->source_node);14628 ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
14618 if (union_val == nullptr)14629 if (union_val == nullptr)
14619 return ira->codegen->invalid_instruction;14630 return ira->codegen->invalid_instruction;
14620 if (type_is_invalid(union_val->type))14631 if (type_is_invalid(union_val->type))
...@@ -14811,7 +14822,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -14811,7 +14822,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
14811 return ira->codegen->invalid_instruction;14822 return ira->codegen->invalid_instruction;
1481214823
14813 assert(container_ptr->value.type->id == ZigTypeIdPointer);14824 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14814 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);14825 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
14815 if (child_val == nullptr)14826 if (child_val == nullptr)
14816 return ira->codegen->invalid_instruction;14827 return ira->codegen->invalid_instruction;
1481714828
...@@ -14837,7 +14848,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -14837,7 +14848,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
14837 return ira->codegen->invalid_instruction;14848 return ira->codegen->invalid_instruction;
1483814849
14839 assert(container_ptr->value.type->id == ZigTypeIdPointer);14850 assert(container_ptr->value.type->id == ZigTypeIdPointer);
14840 ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node);14851 ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
14841 if (child_val == nullptr)14852 if (child_val == nullptr)
14842 return ira->codegen->invalid_instruction;14853 return ira->codegen->invalid_instruction;
14843 ZigType *child_type = child_val->data.x_type;14854 ZigType *child_type = child_val->data.x_type;
...@@ -15112,7 +15123,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -15112,7 +15123,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
15112 if (!container_ptr_val)15123 if (!container_ptr_val)
15113 return ira->codegen->invalid_instruction;15124 return ira->codegen->invalid_instruction;
1511415125
15115 ConstExprValue *namespace_val = ir_const_ptr_pointee(ira, container_ptr_val,15126 ConstExprValue *namespace_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val,
15116 field_ptr_instruction->base.source_node);15127 field_ptr_instruction->base.source_node);
15117 if (namespace_val == nullptr)15128 if (namespace_val == nullptr)
15118 return ira->codegen->invalid_instruction;15129 return ira->codegen->invalid_instruction;
...@@ -15187,7 +15198,7 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc...@@ -15187,7 +15198,7 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc
15187 }15198 }
15188 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {15199 if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) {
15189 if (instr_is_comptime(casted_value)) {15200 if (instr_is_comptime(casted_value)) {
15190 ConstExprValue *dest_val = ir_const_ptr_pointee(ira, &ptr->value, store_ptr_instruction->base.source_node);15201 ConstExprValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, store_ptr_instruction->base.source_node);
15191 if (dest_val == nullptr)15202 if (dest_val == nullptr)
15192 return ira->codegen->invalid_instruction;15203 return ira->codegen->invalid_instruction;
15193 if (dest_val->special != ConstValSpecialRuntime) {15204 if (dest_val->special != ConstValSpecialRuntime) {
...@@ -15735,7 +15746,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -15735,7 +15746,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
15735 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);15746 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
15736 if (!val)15747 if (!val)
15737 return ira->codegen->invalid_instruction;15748 return ira->codegen->invalid_instruction;
15738 ConstExprValue *maybe_val = ir_const_ptr_pointee(ira, val, unwrap_maybe_instruction->base.source_node);15749 ConstExprValue *maybe_val = const_ptr_pointee(ira, ira->codegen, val, unwrap_maybe_instruction->base.source_node);
15739 if (maybe_val == nullptr)15750 if (maybe_val == nullptr)
15740 return ira->codegen->invalid_instruction;15751 return ira->codegen->invalid_instruction;
1574115752
...@@ -16032,7 +16043,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -16032,7 +16043,7 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
16032 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;16043 ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type;
16033 ConstExprValue *pointee_val = nullptr;16044 ConstExprValue *pointee_val = nullptr;
16034 if (instr_is_comptime(target_value_ptr)) {16045 if (instr_is_comptime(target_value_ptr)) {
16035 pointee_val = ir_const_ptr_pointee(ira, &target_value_ptr->value, target_value_ptr->source_node);16046 pointee_val = const_ptr_pointee(ira, ira->codegen, &target_value_ptr->value, target_value_ptr->source_node);
16036 if (pointee_val == nullptr)16047 if (pointee_val == nullptr)
16037 return ira->codegen->invalid_instruction;16048 return ira->codegen->invalid_instruction;
16038 16049
...@@ -16167,7 +16178,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -16167,7 +16178,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
16167 if (!target_value_ptr)16178 if (!target_value_ptr)
16168 return ira->codegen->invalid_instruction;16179 return ira->codegen->invalid_instruction;
1616916180
16170 ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, target_val_ptr, instruction->base.source_node);16181 ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);
16171 if (pointee_val == nullptr)16182 if (pointee_val == nullptr)
16172 return ira->codegen->invalid_instruction;16183 return ira->codegen->invalid_instruction;
1617316184
...@@ -18882,18 +18893,18 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -18882,18 +18893,18 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
18882 if (array_type->id == ZigTypeIdPointer) {18893 if (array_type->id == ZigTypeIdPointer) {
18883 ZigType *child_array_type = array_type->data.pointer.child_type;18894 ZigType *child_array_type = array_type->data.pointer.child_type;
18884 assert(child_array_type->id == ZigTypeIdArray);18895 assert(child_array_type->id == ZigTypeIdArray);
18885 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);18896 parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
18886 if (parent_ptr == nullptr)18897 if (parent_ptr == nullptr)
18887 return ira->codegen->invalid_instruction;18898 return ira->codegen->invalid_instruction;
1888818899
18889 array_val = ir_const_ptr_pointee(ira, parent_ptr, instruction->base.source_node);18900 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
18890 if (array_val == nullptr)18901 if (array_val == nullptr)
18891 return ira->codegen->invalid_instruction;18902 return ira->codegen->invalid_instruction;
1889218903
18893 rel_end = child_array_type->data.array.len;18904 rel_end = child_array_type->data.array.len;
18894 abs_offset = 0;18905 abs_offset = 0;
18895 } else {18906 } else {
18896 array_val = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);18907 array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
18897 if (array_val == nullptr)18908 if (array_val == nullptr)
18898 return ira->codegen->invalid_instruction;18909 return ira->codegen->invalid_instruction;
18899 rel_end = array_type->data.array.len;18910 rel_end = array_type->data.array.len;
...@@ -18902,7 +18913,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -18902,7 +18913,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
18902 }18913 }
18903 } else if (array_type->id == ZigTypeIdPointer) {18914 } else if (array_type->id == ZigTypeIdPointer) {
18904 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);18915 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
18905 parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);18916 parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
18906 if (parent_ptr == nullptr)18917 if (parent_ptr == nullptr)
18907 return ira->codegen->invalid_instruction;18918 return ira->codegen->invalid_instruction;
1890818919
...@@ -18942,7 +18953,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -18942,7 +18953,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
18942 zig_panic("TODO slice of ptr cast from function");18953 zig_panic("TODO slice of ptr cast from function");
18943 }18954 }
18944 } else if (is_slice(array_type)) {18955 } else if (is_slice(array_type)) {
18945 ConstExprValue *slice_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node);18956 ConstExprValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
18946 if (slice_ptr == nullptr)18957 if (slice_ptr == nullptr)
18947 return ira->codegen->invalid_instruction;18958 return ira->codegen->invalid_instruction;
1894818959
...@@ -19351,7 +19362,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -19351,7 +19362,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
19351 {19362 {
19352 BigInt *op1_bigint = &casted_op1->value.data.x_bigint;19363 BigInt *op1_bigint = &casted_op1->value.data.x_bigint;
19353 BigInt *op2_bigint = &casted_op2->value.data.x_bigint;19364 BigInt *op2_bigint = &casted_op2->value.data.x_bigint;
19354 ConstExprValue *pointee_val = ir_const_ptr_pointee(ira, &casted_result_ptr->value, casted_result_ptr->source_node);19365 ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, &casted_result_ptr->value, casted_result_ptr->source_node);
19355 if (pointee_val == nullptr)19366 if (pointee_val == nullptr)
19356 return ira->codegen->invalid_instruction;19367 return ira->codegen->invalid_instruction;
19357 BigInt *dest_bigint = &pointee_val->data.x_bigint;19368 BigInt *dest_bigint = &pointee_val->data.x_bigint;
...@@ -19450,7 +19461,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -19450,7 +19461,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
19450 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);19461 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
19451 if (!ptr_val)19462 if (!ptr_val)
19452 return ira->codegen->invalid_instruction;19463 return ira->codegen->invalid_instruction;
19453 ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node);19464 ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node);
19454 if (err_union_val == nullptr)19465 if (err_union_val == nullptr)
19455 return ira->codegen->invalid_instruction;19466 return ira->codegen->invalid_instruction;
19456 if (err_union_val->special != ConstValSpecialRuntime) {19467 if (err_union_val->special != ConstValSpecialRuntime) {
...@@ -19502,7 +19513,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -19502,7 +19513,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
19502 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);19513 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
19503 if (!ptr_val)19514 if (!ptr_val)
19504 return ira->codegen->invalid_instruction;19515 return ira->codegen->invalid_instruction;
19505 ConstExprValue *err_union_val = ir_const_ptr_pointee(ira, ptr_val, instruction->base.source_node);19516 ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.source_node);
19506 if (err_union_val == nullptr)19517 if (err_union_val == nullptr)
19507 return ira->codegen->invalid_instruction;19518 return ira->codegen->invalid_instruction;
19508 if (err_union_val->special != ConstValSpecialRuntime) {19519 if (err_union_val->special != ConstValSpecialRuntime) {
...@@ -20132,7 +20143,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20132,7 +20143,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20132 zig_unreachable();20143 zig_unreachable();
20133}20144}
2013420145
20135static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t *buf, ConstExprValue *val) {20146static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val) {
20136 Error err;20147 Error err;
20137 assert(val->special == ConstValSpecialStatic);20148 assert(val->special == ConstValSpecialStatic);
20138 switch (val->type->id) {20149 switch (val->type->id) {
...@@ -20156,22 +20167,22 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t...@@ -20156,22 +20167,22 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t
20156 return ErrorNone;20167 return ErrorNone;
20157 case ZigTypeIdInt:20168 case ZigTypeIdInt:
20158 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,20169 bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
20159 ira->codegen->is_big_endian, val->type->data.integral.is_signed);20170 codegen->is_big_endian, val->type->data.integral.is_signed);
20160 return ErrorNone;20171 return ErrorNone;
20161 case ZigTypeIdFloat:20172 case ZigTypeIdFloat:
20162 float_read_ieee597(val, buf, ira->codegen->is_big_endian);20173 float_read_ieee597(val, buf, codegen->is_big_endian);
20163 return ErrorNone;20174 return ErrorNone;
20164 case ZigTypeIdPointer:20175 case ZigTypeIdPointer:
20165 {20176 {
20166 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;20177 val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
20167 BigInt bn;20178 BigInt bn;
20168 bigint_read_twos_complement(&bn, buf, ira->codegen->builtin_types.entry_usize->data.integral.bit_count,20179 bigint_read_twos_complement(&bn, buf, codegen->builtin_types.entry_usize->data.integral.bit_count,
20169 ira->codegen->is_big_endian, false);20180 codegen->is_big_endian, false);
20170 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);20181 val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn);
20171 return ErrorNone;20182 return ErrorNone;
20172 }20183 }
20173 case ZigTypeIdArray: {20184 case ZigTypeIdArray: {
20174 uint64_t elem_size = type_size(ira->codegen, val->type->data.array.child_type);20185 uint64_t elem_size = type_size(codegen, val->type->data.array.child_type);
20175 size_t len = val->type->data.array.len;20186 size_t len = val->type->data.array.len;
2017620187
20177 switch (val->data.x_array.special) {20188 switch (val->data.x_array.special) {
...@@ -20181,7 +20192,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t...@@ -20181,7 +20192,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t
20181 ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i];20192 ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i];
20182 elem->special = ConstValSpecialStatic;20193 elem->special = ConstValSpecialStatic;
20183 elem->type = val->type->data.array.child_type;20194 elem->type = val->type->data.array.child_type;
20184 if ((err = buf_read_value_bytes(ira, source_node, buf + (elem_size * i), elem)))20195 if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem)))
20185 return err;20196 return err;
20186 }20197 }
20187 break;20198 break;
...@@ -20196,10 +20207,10 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t...@@ -20196,10 +20207,10 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t
20196 case ZigTypeIdStruct:20207 case ZigTypeIdStruct:
20197 switch (val->type->data.structure.layout) {20208 switch (val->type->data.structure.layout) {
20198 case ContainerLayoutAuto: {20209 case ContainerLayoutAuto: {
20199 ErrorMsg *msg = ir_add_error_node(ira, source_node,20210 ErrorMsg *msg = opt_ir_add_error_node(ira, codegen, source_node,
20200 buf_sprintf("non-extern, non-packed struct '%s' cannot have its bytes reinterpreted",20211 buf_sprintf("non-extern, non-packed struct '%s' cannot have its bytes reinterpreted",
20201 buf_ptr(&val->type->name)));20212 buf_ptr(&val->type->name)));
20202 add_error_note(ira->codegen, msg, val->type->data.structure.decl_node,20213 add_error_note(codegen, msg, val->type->data.structure.decl_node,
20203 buf_sprintf("declared here"));20214 buf_sprintf("declared here"));
20204 return ErrorSemanticAnalyzeFail;20215 return ErrorSemanticAnalyzeFail;
20205 }20216 }
...@@ -20213,10 +20224,10 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t...@@ -20213,10 +20224,10 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t
20213 field_val->type = type_field->type_entry;20224 field_val->type = type_field->type_entry;
20214 if (type_field->gen_index == SIZE_MAX)20225 if (type_field->gen_index == SIZE_MAX)
20215 continue;20226 continue;
20216 size_t offset = LLVMOffsetOfElement(ira->codegen->target_data_ref, val->type->type_ref,20227 size_t offset = LLVMOffsetOfElement(codegen->target_data_ref, val->type->type_ref,
20217 type_field->gen_index);20228 type_field->gen_index);
20218 uint8_t *new_buf = buf + offset;20229 uint8_t *new_buf = buf + offset;
20219 if ((err = buf_read_value_bytes(ira, source_node, new_buf, field_val)))20230 if ((err = buf_read_value_bytes(ira, codegen, source_node, new_buf, field_val)))
20220 return err;20231 return err;
20221 }20232 }
20222 return ErrorNone;20233 return ErrorNone;
...@@ -20327,7 +20338,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct...@@ -20327,7 +20338,7 @@ static IrInstruction *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruct
20327 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);20338 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);
20328 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);20339 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
20329 buf_write_value_bytes(ira->codegen, buf, val);20340 buf_write_value_bytes(ira->codegen, buf, val);
20330 if ((err = buf_read_value_bytes(ira, instruction->base.source_node, buf, &result->value)))20341 if ((err = buf_read_value_bytes(ira, ira->codegen, instruction->base.source_node, buf, &result->value)))
20331 return ira->codegen->invalid_instruction;20342 return ira->codegen->invalid_instruction;
20332 return result;20343 return result;
20333 }20344 }
src/ir.hpp+4-1
...@@ -22,6 +22,9 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_...@@ -22,6 +22,9 @@ ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_
22 ZigType *expected_type, AstNode *expected_type_source_node);22 ZigType *expected_type, AstNode *expected_type_source_node);
2323
24bool ir_has_side_effects(IrInstruction *instruction);24bool ir_has_side_effects(IrInstruction *instruction);
25ConstExprValue *const_ptr_pointee(CodeGen *codegen, ConstExprValue *const_val);25
26struct IrAnalyze;
27ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val,
28 AstNode *source_node);
2629
27#endif30#endif