IR: fix array concatenation

all tests passing
This commit is contained in:
Andrew Kelley 2017-01-12 15:10:58 -05:00
parent d784705353
commit 18f248b94d
3 changed files with 17 additions and 12 deletions

View File

@ -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<ConstExprValue>(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<ConstExprValue>(new_len);
out_array_val->data.x_array.size = new_len;

View File

@ -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;
}

View File

@ -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) {