From db928915878c64f9e5c479739bd768bd4ac0b912 Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Sun, 6 Jan 2019 17:48:31 +0100 Subject: Respect the type system instead of ConstExprValue when getting field --- src/ir.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 400b07368b..d74bef2424 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -14577,8 +14577,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ return ira->codegen->invalid_instruction; if (type_is_invalid(struct_val->type)) return ira->codegen->invalid_instruction; - ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; - ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, is_const, is_volatile, PtrLenSingle, align_bytes, (uint32_t)(ptr_bit_offset + field->bit_offset_in_host), (uint32_t)host_int_bytes_for_result_type); -- cgit v1.2.3 From e410b1f915974fe3daeebae324e8c4e4b42090dd Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Sun, 6 Jan 2019 17:49:24 +0100 Subject: Implemented buf_read_value_bytes for ZigTypeIdArray * Only for x_array.special == ConstArraySpecialNone --- src/ir.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index d74bef2424..2353bb1086 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -20179,8 +20179,29 @@ static Error buf_read_value_bytes(IrAnalyze *ira, AstNode *source_node, uint8_t val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn); return ErrorNone; } - case ZigTypeIdArray: - zig_panic("TODO buf_read_value_bytes array type"); + case ZigTypeIdArray: { + uint64_t elem_size = type_size(ira->codegen, val->type->data.array.child_type); + size_t len = val->type->data.array.len; + + switch (val->data.x_array.special) { + case ConstArraySpecialNone: + val->data.x_array.data.s_none.elements = create_const_vals(len); + for (size_t i = 0; i < len; i++) { + ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i]; + elem->special = ConstValSpecialStatic; + elem->type = val->type->data.array.child_type; + if ((err = buf_read_value_bytes(ira, source_node, buf + (elem_size * i), elem))) + return err; + } + break; + case ConstArraySpecialUndef: + zig_panic("TODO buf_read_value_bytes ConstArraySpecialUndef array type"); + case ConstArraySpecialBuf: + zig_panic("TODO buf_read_value_bytes ConstArraySpecialBuf array type"); + } + + return ErrorNone; + } case ZigTypeIdStruct: switch (val->type->data.structure.layout) { case ContainerLayoutAuto: { -- cgit v1.2.3 From 55e95daf543a27961fe9ca7a998d3cbd25d2973b Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Sun, 6 Jan 2019 17:53:34 +0100 Subject: Fixed issue where TypeInfo would use types from a prev CodeGen instance When doing multible codegen passes (such as building compiler_rt and then something else) the TypeInfo cache code would point to types from the prev code gen (such as the prev 'bool' type), giving us errors like "expected type 'bool', but found type 'bool'" This disabling of caching might have a performance hit, but correctness is better than speed, so let's have this for now, until someone optimizes this correctly (probably in stage2) --- src/ir.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 2353bb1086..4e401b7249 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16882,16 +16882,12 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { Error err; - static ConstExprValue *type_info_var = nullptr; // TODO oops this global variable made it past code review - static ZigType *type_info_type = nullptr; // TODO oops this global variable made it past code review - if (type_info_var == nullptr) { - type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); - assert(type_info_var->type->id == ZigTypeIdMetaType); + ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); // TODO oops this global variable made it past code review + assert(type_info_var->type->id == ZigTypeIdMetaType); + assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); - assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); - type_info_type = type_info_var->data.x_type; - assert(type_info_type->id == ZigTypeIdUnion); - } + ZigType *type_info_type = type_info_var->data.x_type; // TODO oops this global variable made it past code review + assert(type_info_type->id == ZigTypeIdUnion); if (type_name == nullptr && root == nullptr) return type_info_type; -- cgit v1.2.3 From da08525bb31c3608667254132b65e409f5869a03 Mon Sep 17 00:00:00 2001 From: Jimmi HC Date: Sun, 6 Jan 2019 18:02:00 +0100 Subject: Removed oops comments --- src/ir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 4e401b7249..531b705538 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16882,11 +16882,11 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { Error err; - ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); // TODO oops this global variable made it past code review + ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); assert(type_info_var->type->id == ZigTypeIdMetaType); assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); - ZigType *type_info_type = type_info_var->data.x_type; // TODO oops this global variable made it past code review + ZigType *type_info_type = type_info_var->data.x_type; assert(type_info_type->id == ZigTypeIdUnion); if (type_name == nullptr && root == nullptr) -- cgit v1.2.3