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...@@ -4314,12 +4314,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
4314 if (continue_expr_node) {4314 if (continue_expr_node) {
4315 ir_set_cursor_at_end(irb, continue_block);4315 ir_set_cursor_at_end(irb, continue_block);
4316 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope);4316 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope);
4317 if (expr_result == irb->codegen->invalid_instruction)
4318 return expr_result;
4317 if (!instr_is_unreachable(expr_result))4319 if (!instr_is_unreachable(expr_result))
4318 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));4320 ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime));
4319 }4321 }
43204322
4321 ir_set_cursor_at_end(irb, cond_block);4323 ir_set_cursor_at_end(irb, cond_block);
4322 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);4324 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;
4323 if (!instr_is_unreachable(cond_val)) {4327 if (!instr_is_unreachable(cond_val)) {
4324 ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,4328 ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
4325 body_block, end_block, is_comptime));4329 body_block, end_block, is_comptime));
...@@ -4332,6 +4336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -4332,6 +4336,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
4332 loop_stack_item->continue_block = continue_block;4336 loop_stack_item->continue_block = continue_block;
4333 loop_stack_item->is_comptime = is_comptime;4337 loop_stack_item->is_comptime = is_comptime;
4334 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, scope);4338 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;
4335 irb->loop_stack.pop();4341 irb->loop_stack.pop();
43364342
4337 if (!instr_is_unreachable(body_result))4343 if (!instr_is_unreachable(body_result))
...@@ -7215,22 +7221,21 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -7215,22 +7221,21 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
7215 TypeTableEntry *result_type;7221 TypeTableEntry *result_type;
7216 ConstExprValue *out_array_val;7222 ConstExprValue *out_array_val;
7217 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);7223 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);
7219 if (op1_canon_type->id == TypeTableEntryIdArray || op2_canon_type->id == TypeTableEntryIdArray) {7224 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
7222 out_array_val = out_val;7227 out_array_val = out_val;
7223 } else {7228 } else {
7229 new_len += 1; // null byte
7230
7224 result_type = get_pointer_to_type(ira->codegen, child_type, true);7231 result_type = get_pointer_to_type(ira->codegen, child_type, true);
72257232
7226 out_array_val = allocate<ConstExprValue>(1);7233 out_array_val = allocate<ConstExprValue>(1);
7227 out_array_val->special = ConstValSpecialStatic;7234 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);
7229 out_val->data.x_ptr.base_ptr = out_array_val;7236 out_val->data.x_ptr.base_ptr = out_array_val;
7230 out_val->data.x_ptr.index = 0;7237 out_val->data.x_ptr.index = 0;
7231 out_val->data.x_ptr.special = ConstPtrSpecialCStr;7238 out_val->data.x_ptr.special = ConstPtrSpecialCStr;
7232
7233 new_len += 1; // null byte
7234 }7239 }
7235 out_array_val->data.x_array.elements = allocate<ConstExprValue>(new_len);7240 out_array_val->data.x_array.elements = allocate<ConstExprValue>(new_len);
7236 out_array_val->data.x_array.size = new_len;7241 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...@@ -156,7 +156,7 @@ static TldVar *create_global_var(Context *c, Buf *name, ConstExprValue *var_valu
156}156}
157157
158static Tld *create_global_str_lit_var(Context *c, Buf *name, Buf *value) {158static 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);
160 return &tld_var->base;160 return &tld_var->base;
161}161}
162162
test/run_tests.cpp+6-6
...@@ -1895,7 +1895,7 @@ extern char (*fn_ptr2)(int, float);...@@ -1895,7 +1895,7 @@ extern char (*fn_ptr2)(int, float);
18951895
1896 add_parseh_case("#define string", AllowWarningsNo, R"SOURCE(1896 add_parseh_case("#define string", AllowWarningsNo, R"SOURCE(
1897#define foo "a string"1897#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
1900 add_parseh_case("__cdecl doesn't mess up function pointers", AllowWarningsNo, R"SOURCE(1900 add_parseh_case("__cdecl doesn't mess up function pointers", AllowWarningsNo, R"SOURCE(
1901void foo(void (__cdecl *fn_ptr)(void));1901void foo(void (__cdecl *fn_ptr)(void));
...@@ -1909,18 +1909,18 @@ void foo(void (__cdecl *fn_ptr)(void));...@@ -1909,18 +1909,18 @@ void foo(void (__cdecl *fn_ptr)(void));
1909struct type {1909struct type {
1910 int defer;1910 int defer;
1911};1911};
1912 )SOURCE", 2, R"(export struct struct_type {1912 )SOURCE", 2, R"(pub const struct_type = extern struct {
1913 @"defer": c_int,1913 @"defer": c_int,
1914})", R"(pub const @"type" = struct_type;)");1914};)", R"(pub const @"type" = struct_type;)");
19151915
1916 add_parseh_case("macro defines string literal with octal", AllowWarningsNo, R"SOURCE(1916 add_parseh_case("macro defines string literal with octal", AllowWarningsNo, R"SOURCE(
1917#define FOO "aoeu\023 derp"1917#define FOO "aoeu\023 derp"
1918#define FOO2 "aoeu\0234 derp"1918#define FOO2 "aoeu\0234 derp"
1919#define FOO_CHAR '\077'1919#define FOO_CHAR '\077'
1920 )SOURCE", 3,1920 )SOURCE", 3,
1921 R"(pub const FOO = c"aoeu\x13 derp")",1921 R"(pub const FOO: &const u8 = &(c str lit);)",
1922 R"(pub const FOO2 = c"aoeu\x134 derp")",1922 R"(pub const FOO2: &const u8 = &(c str lit);)",
1923 R"(pub const FOO_CHAR = '?')");1923 R"(pub const FOO_CHAR = 63;)");
1924}1924}
19251925
1926static void run_self_hosted_test(bool is_release_mode) {1926static void run_self_hosted_test(bool is_release_mode) {