From 18f248b94d1c936328058a6d67afe0003f022c5c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 12 Jan 2017 15:10:58 -0500 Subject: [PATCH] IR: fix array concatenation all tests passing --- src/ir.cpp | 15 ++++++++++----- src/parseh.cpp | 2 +- test/run_tests.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ir.cpp b/src/ir.cpp index c5293e2af1..8da0f13498 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4314,12 +4314,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n if (continue_expr_node) { ir_set_cursor_at_end(irb, continue_block); IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope); + if (expr_result == irb->codegen->invalid_instruction) + return expr_result; if (!instr_is_unreachable(expr_result)) ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime)); } ir_set_cursor_at_end(irb, cond_block); IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); + if (cond_val == irb->codegen->invalid_instruction) + return cond_val; if (!instr_is_unreachable(cond_val)) { ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, body_block, end_block, is_comptime)); @@ -4332,6 +4336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n loop_stack_item->continue_block = continue_block; loop_stack_item->is_comptime = is_comptime; IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, scope); + if (body_result == irb->codegen->invalid_instruction) + return body_result; irb->loop_stack.pop(); if (!instr_is_unreachable(body_result)) @@ -7215,22 +7221,21 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * TypeTableEntry *result_type; ConstExprValue *out_array_val; size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); - TypeTableEntry *out_array_type = get_array_type(ira->codegen, child_type, new_len); if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) { - result_type = out_array_type; + result_type = get_array_type(ira->codegen, child_type, new_len); out_array_val = out_val; } else { + new_len += 1; // null byte + result_type = get_pointer_to_type(ira->codegen, child_type, true); out_array_val = allocate(1); out_array_val->special = ConstValSpecialStatic; - out_array_val->type = out_array_type; + out_array_val->type = get_array_type(ira->codegen, child_type, new_len); out_val->data.x_ptr.base_ptr = out_array_val; out_val->data.x_ptr.index = 0; out_val->data.x_ptr.special = ConstPtrSpecialCStr; - - new_len += 1; // null byte } out_array_val->data.x_array.elements = allocate(new_len); out_array_val->data.x_array.size = new_len; diff --git a/src/parseh.cpp b/src/parseh.cpp index c2546765e4..15283e9597 100644 --- a/src/parseh.cpp +++ b/src/parseh.cpp @@ -156,7 +156,7 @@ static TldVar *create_global_var(Context *c, Buf *name, ConstExprValue *var_valu } static Tld *create_global_str_lit_var(Context *c, Buf *name, Buf *value) { - TldVar *tld_var = create_global_var(c, name, create_const_str_lit(c->codegen, value), true); + TldVar *tld_var = create_global_var(c, name, create_const_c_str_lit(c->codegen, value), true); return &tld_var->base; } diff --git a/test/run_tests.cpp b/test/run_tests.cpp index e5badea1c8..2a9bb72670 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1895,7 +1895,7 @@ extern char (*fn_ptr2)(int, float); add_parseh_case("#define string", AllowWarningsNo, R"SOURCE( #define foo "a string" - )SOURCE", 1, "pub const foo = c\"a string\";"); + )SOURCE", 1, "pub const foo: &const u8 = &(c str lit);"); add_parseh_case("__cdecl doesn't mess up function pointers", AllowWarningsNo, R"SOURCE( void foo(void (__cdecl *fn_ptr)(void)); @@ -1909,18 +1909,18 @@ void foo(void (__cdecl *fn_ptr)(void)); struct type { int defer; }; - )SOURCE", 2, R"(export struct struct_type { + )SOURCE", 2, R"(pub const struct_type = extern struct { @"defer": c_int, -})", R"(pub const @"type" = struct_type;)"); +};)", R"(pub const @"type" = struct_type;)"); add_parseh_case("macro defines string literal with octal", AllowWarningsNo, R"SOURCE( #define FOO "aoeu\023 derp" #define FOO2 "aoeu\0234 derp" #define FOO_CHAR '\077' )SOURCE", 3, - R"(pub const FOO = c"aoeu\x13 derp")", - R"(pub const FOO2 = c"aoeu\x134 derp")", - R"(pub const FOO_CHAR = '?')"); + R"(pub const FOO: &const u8 = &(c str lit);)", + R"(pub const FOO2: &const u8 = &(c str lit);)", + R"(pub const FOO_CHAR = 63;)"); } static void run_self_hosted_test(bool is_release_mode) {