authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-12 15:10:58-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-12 15:10:58-05:00
log18f248b94d1c936328058a6d67afe0003f022c5c
tree3ebdde91c9a5156a145e58e737148afc37851d2c
parentd7847053531c3352db8355e21e54b102958cbb8a

IR: fix array concatenation

all tests passing

3 files changed, 17 insertions(+), 12 deletions(-)

src/ir.cpp+10-5
......@@ -4314,12 +4314,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
43144314 if (continue_expr_node) {
43154315 ir_set_cursor_at_end(irb, continue_block);
43164316 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope);
4317 if (expr_result == irb->codegen->invalid_instruction)
4318 return expr_result;
43174319 if (!instr_is_unreachable(expr_result))
43184320 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));
43194321 }
43204322
43214323 ir_set_cursor_at_end(irb, cond_block);
43224324 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
4325 if (cond_val == irb->codegen->invalid_instruction)
4326 return cond_val;
43234327 if (!instr_is_unreachable(cond_val)) {
43244328 ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
43254329 body_block, end_block, is_comptime));
......@@ -4332,6 +4336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
43324336 loop_stack_item->continue_block = continue_block;
43334337 loop_stack_item->is_comptime = is_comptime;
43344338 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, scope);
4339 if (body_result == irb->codegen->invalid_instruction)
4340 return body_result;
43354341 irb->loop_stack.pop();
43364342
43374343 if (!instr_is_unreachable(body_result))
......@@ -7215,22 +7221,21 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
72157221 TypeTableEntry *result_type;
72167222 ConstExprValue *out_array_val;
72177223 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
7218 TypeTableEntry *out_array_type = get_array_type(ira->codegen, child_type, new_len);
72197224 if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) {
7220 result_type = out_array_type;
7225 result_type = get_array_type(ira->codegen, child_type, new_len);
72217226
72227227 out_array_val = out_val;
72237228 } else {
7229 new_len += 1; // null byte
7230
72247231 result_type = get_pointer_to_type(ira->codegen, child_type, true);
72257232
72267233 out_array_val = allocate<ConstExprValue>(1);
72277234 out_array_val->special = ConstValSpecialStatic;
7228 out_array_val->type = out_array_type;
7235 out_array_val->type = get_array_type(ira->codegen, child_type, new_len);
72297236 out_val->data.x_ptr.base_ptr = out_array_val;
72307237 out_val->data.x_ptr.index = 0;
72317238 out_val->data.x_ptr.special = ConstPtrSpecialCStr;
7232
7233 new_len += 1; // null byte
72347239 }
72357240 out_array_val->data.x_array.elements = allocate<ConstExprValue>(new_len);
72367241 out_array_val->data.x_array.size = new_len;
src/parseh.cpp+1-1
......@@ -156,7 +156,7 @@ static TldVar *create_global_var(Context *c, Buf *name, ConstExprValue *var_valu
156156}
157157
158158static Tld *create_global_str_lit_var(Context *c, Buf *name, Buf *value) {
159 TldVar *tld_var = create_global_var(c, name, create_const_str_lit(c->codegen, value), true);
159 TldVar *tld_var = create_global_var(c, name, create_const_c_str_lit(c->codegen, value), true);
160160 return &tld_var->base;
161161}
162162
test/run_tests.cpp+6-6
......@@ -1895,7 +1895,7 @@ extern char (*fn_ptr2)(int, float);
18951895
18961896 add_parseh_case("#define string", AllowWarningsNo, R"SOURCE(
18971897#define foo "a string"
1898 )SOURCE", 1, "pub const foo = c\"a string\";");
1898 )SOURCE", 1, "pub const foo: &const u8 = &(c str lit);");
18991899
19001900 add_parseh_case("__cdecl doesn't mess up function pointers", AllowWarningsNo, R"SOURCE(
19011901void foo(void (__cdecl *fn_ptr)(void));
......@@ -1909,18 +1909,18 @@ void foo(void (__cdecl *fn_ptr)(void));
19091909struct type {
19101910 int defer;
19111911};
1912 )SOURCE", 2, R"(export struct struct_type {
1912 )SOURCE", 2, R"(pub const struct_type = extern struct {
19131913 @"defer": c_int,
1914})", R"(pub const @"type" = struct_type;)");
1914};)", R"(pub const @"type" = struct_type;)");
19151915
19161916 add_parseh_case("macro defines string literal with octal", AllowWarningsNo, R"SOURCE(
19171917#define FOO "aoeu\023 derp"
19181918#define FOO2 "aoeu\0234 derp"
19191919#define FOO_CHAR '\077'
19201920 )SOURCE", 3,
1921 R"(pub const FOO = c"aoeu\x13 derp")",
1922 R"(pub const FOO2 = c"aoeu\x134 derp")",
1923 R"(pub const FOO_CHAR = '?')");
1921 R"(pub const FOO: &const u8 = &(c str lit);)",
1922 R"(pub const FOO2: &const u8 = &(c str lit);)",
1923 R"(pub const FOO_CHAR = 63;)");
19241924}
19251925
19261926static void run_self_hosted_test(bool is_release_mode) {