From 7d9a9a2283c6c0cbd1e1034b2496d4898335beb0 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 12 Jan 2020 13:53:51 +0000 Subject: [PATCH 1/5] Add extra check for opaque types --- src/ir.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index 2de2b2669..8af0b85bd 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4713,6 +4713,10 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { Type *t = base_type(type_deref(ir_type(s))); Type *result_type = nullptr; + if (t->kind == Type_Opaque) { + t = t->Opaque.elem; + } + if (is_type_struct(t)) { result_type = alloc_type_pointer(t->Struct.fields[index]->type); } else if (is_type_union(t)) { @@ -4896,6 +4900,9 @@ irValue *ir_emit_deep_field_gep(irProcedure *proc, irValue *e, Selection sel) { // e = ir_emit_ptr_offset(proc, e, v_zero); // TODO(bill): Do I need these copies? } type = core_type(type); + if (type->kind == Type_Opaque) { + type = type->Opaque.elem; + } if (is_type_quaternion(type)) { e = ir_emit_struct_ep(proc, e, index); From 04f7225ea5419adac67adf466a528de487c3dbd9 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 14 Jan 2020 17:36:37 +0000 Subject: [PATCH 2/5] Exact value zero value for `T{}` of basic types --- src/check_expr.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/check_expr.cpp b/src/check_expr.cpp index f23c47a2e..884dc8de3 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -8391,6 +8391,33 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type bits |= bit; } o->value = exact_value_u64(bits); + } else if (is_type_constant_type(type) && cl->elems.count == 0) { + ExactValue value = exact_value_compound(node); + Type *bt = core_type(type); + if (bt->kind == Type_Basic) { + if (bt->Basic.flags & BasicFlag_Boolean) { + value = exact_value_bool(false); + } else if (bt->Basic.flags & BasicFlag_Integer) { + value = exact_value_i64(0); + } else if (bt->Basic.flags & BasicFlag_Unsigned) { + value = exact_value_i64(0); + } else if (bt->Basic.flags & BasicFlag_Float) { + value = exact_value_float(0); + } else if (bt->Basic.flags & BasicFlag_Complex) { + value = exact_value_complex(0, 0); + } else if (bt->Basic.flags & BasicFlag_Quaternion) { + value = exact_value_quaternion(0, 0, 0, 0); + } else if (bt->Basic.flags & BasicFlag_Pointer) { + value = exact_value_pointer(0); + } else if (bt->Basic.flags & BasicFlag_String) { + String empty_string = {}; + value = exact_value_string(empty_string); + } else if (bt->Basic.flags & BasicFlag_Rune) { + value = exact_value_i64(0); + } + } + + o->value = value; } else { o->value = exact_value_compound(node); } From ae7cbd5171ef1ae1d27c354bab04c2e6d241176a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 14 Jan 2020 17:37:45 +0000 Subject: [PATCH 3/5] Add debug info for enumerated arrays --- src/ir.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index de7bfef82..4630153a0 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -2664,6 +2664,20 @@ irDebugInfo *ir_add_debug_info_type(irModule *module, Type *type, Entity *e, irD return di; } + if (is_type_enumerated_array(type)) { + irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType); + di->CompositeType.size = ir_debug_size_bits(type); + di->CompositeType.align = ir_debug_align_bits(type); + di->CompositeType.tag = irDebugBasicEncoding_array_type; + di->CompositeType.array_count = (i32)type->EnumeratedArray.count; + + map_set(&module->debug_info, hash_type(type), di); + di->CompositeType.base_type = ir_add_debug_info_type(module, type->EnumeratedArray.elem, e, scope, file); + GB_ASSERT(base->kind != Type_Named); + + return di; + } + if (is_type_slice(type)) { // NOTE(lachsinc): Every slice type has its own composite type / field debug infos created. This is sorta wasteful. irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType); From 20b410f149645e02d53fc05bc794fad44f2db5ee Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 15 Jan 2020 11:56:42 +0000 Subject: [PATCH 4/5] Fix #540 --- core/fmt/fmt.odin | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 48efc7e50..ec9a0888d 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1036,7 +1036,8 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "") { continue loop; } } - strings.write_i64(fi.buf, i64(i), 10); + v := i64(i) + info.lower; + strings.write_i64(fi.buf, v, 10); commas += 1; } } From 5db4bd99440c47506a6e22be193efdc235229772 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 15 Jan 2020 12:01:29 +0000 Subject: [PATCH 5/5] Fix #536 --- src/ir.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index 4630153a0..04c57c37b 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3931,7 +3931,7 @@ irValue *ir_addr_get_ptr(irProcedure *proc, irAddr const &addr) { } irValue *ir_build_addr_ptr(irProcedure *proc, Ast *expr) { - irAddr const &addr = ir_build_addr(proc, expr); + irAddr addr = ir_build_addr(proc, expr); return ir_addr_get_ptr(proc, addr); } @@ -6609,7 +6609,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu case BuiltinProc_swizzle: { ir_emit_comment(proc, str_lit("swizzle.begin")); - irAddr const &addr = ir_build_addr(proc, ce->args[0]); + irAddr addr = ir_build_addr(proc, ce->args[0]); isize index_count = ce->args.count-1; if (index_count == 0) { return ir_addr_load(proc, addr); @@ -7730,7 +7730,13 @@ bool ir_is_elem_const(irModule *m, Ast *elem, Type *elem_type) { irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, Ast *expr) { GB_ASSERT(e != nullptr); - GB_ASSERT(e->kind != Entity_Constant); + if (e->kind == Entity_Constant) { + Type *t = default_type(type_of_expr(expr)); + irValue *v = ir_add_module_constant(proc->module, t, e->Constant.value); + irValue *g = ir_add_global_generated(proc->module, ir_type(v), v); + return ir_addr(g); + } + irValue *v = nullptr; irValue **found = map_get(&proc->module->values, hash_entity(e)); @@ -7837,7 +7843,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) { if (sel.entity->type->kind == Type_BitFieldValue) { - irAddr const &addr = ir_build_addr(proc, se->expr); + irAddr addr = ir_build_addr(proc, se->expr); Type *bft = type_deref(ir_addr_type(addr)); if (sel.index.count == 1) { GB_ASSERT(is_type_bit_field(bft)); @@ -9921,7 +9927,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) { case Type_Map: { is_map = true; gbAllocator a = ir_allocator(); - irAddr const &addr = ir_build_addr(proc, expr); + irAddr addr = ir_build_addr(proc, expr); irValue *map = ir_addr_get_ptr(proc, addr); if (is_type_pointer(type_deref(ir_addr_type(addr)))) { map = ir_addr_load(proc, addr);