From 91d911007b8a12405c084cff53237ac26b1f2c5f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 23 Jan 2016 00:53:43 -0700 Subject: [PATCH] codegen: fix field access of arrays also fix error type analyze error --- src/all_types.hpp | 1 + src/analyze.cpp | 9 +++++++-- src/codegen.cpp | 3 ++- std/std.zig | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index 8b5d65584e..f358bd8bd6 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1000,6 +1000,7 @@ struct CodeGen { bool error_during_imports; uint32_t next_node_index; uint32_t next_error_index; + uint32_t error_value_count; TypeTableEntry *err_tag_type; }; diff --git a/src/analyze.cpp b/src/analyze.cpp index 8f19dbd777..c2fe9ba076 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2984,7 +2984,7 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B wanted_type->id == TypeTableEntryIdInt) { BigNum bn; - bignum_init_unsigned(&bn, g->next_error_index); + bignum_init_unsigned(&bn, g->error_value_count); if (bignum_fits_in_bits(&bn, wanted_type->size_in_bits, wanted_type->data.integral.is_signed)) { node->data.fn_call_expr.cast_op = CastOpErrToInt; eval_const_expr_implicit_cast(g, node, expr_node); @@ -4355,10 +4355,15 @@ void semantic_analyze(CodeGen *g) { assert(target_import); target_import->importers.append({import, child}); + } else if (child->type == NodeTypeErrorValueDecl) { + g->error_value_count += 1; } } } } + + g->err_tag_type = get_smallest_unsigned_int_type(g, g->error_value_count); + { auto it = g->import_table.entry_iterator(); for (;;) { @@ -4375,7 +4380,7 @@ void semantic_analyze(CodeGen *g) { } } - g->err_tag_type = get_smallest_unsigned_int_type(g, g->next_error_index); + assert(g->error_value_count == g->next_error_index); { auto it = g->import_table.entry_iterator(); diff --git a/src/codegen.cpp b/src/codegen.cpp index e81437c66a..e2629a44e6 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -27,6 +27,7 @@ CodeGen *codegen_create(Buf *root_source_dir) { g->build_type = CodeGenBuildTypeDebug; g->root_source_dir = root_source_dir; g->next_error_index = 1; + g->error_value_count = 1; return g; } @@ -684,7 +685,7 @@ static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lva { TypeTableEntry *type_entry; LLVMValueRef ptr = gen_field_ptr(g, node, &type_entry); - if (is_lvalue) { + if (is_lvalue || handle_is_ptr(type_entry)) { return ptr; } else { add_debug_source_node(g, node); diff --git a/std/std.zig b/std/std.zig index 102bf1a704..eb1061a6ee 100644 --- a/std/std.zig +++ b/std/std.zig @@ -97,7 +97,7 @@ pub struct OutStream { pub fn flush(os: &OutStream) %void => { const amt_to_write = os.index; os.index = 0; - switch (write(fd, os.buffer.ptr, amt_to_write)) { + switch (write(os.fd, os.buffer.ptr, amt_to_write)) { EINVAL => unreachable{}, EDQUOT => %.DiskQuota, EFBIG => %.FileTooBig,