authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-15 18:41:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-15 18:41:19-07:00
log86f55bce536b6ed678497890f5bd0eed76ebfbb3
tree184f6fd29f016b2a194388d3fa2d7d5d8ce7ed24
parent0311b35a21e9896772cb982750be680b0ef71f1f

add void arrays test


3 files changed, 37 insertions(+), 7 deletions(-)

src/codegen.cpp+17-6
...@@ -514,7 +514,7 @@ static LLVMValueRef gen_array_base_ptr(CodeGen *g, AstNode *node) {...@@ -514,7 +514,7 @@ static LLVMValueRef gen_array_base_ptr(CodeGen *g, AstNode *node) {
514 array_ptr = gen_expr(g, node);514 array_ptr = gen_expr(g, node);
515 }515 }
516516
517 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);517 assert(!array_ptr || LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
518518
519 return array_ptr;519 return array_ptr;
520}520}
...@@ -530,6 +530,10 @@ static LLVMValueRef gen_array_ptr(CodeGen *g, AstNode *node) {...@@ -530,6 +530,10 @@ static LLVMValueRef gen_array_ptr(CodeGen *g, AstNode *node) {
530 LLVMValueRef subscript_value = gen_expr(g, node->data.array_access_expr.subscript);530 LLVMValueRef subscript_value = gen_expr(g, node->data.array_access_expr.subscript);
531 assert(subscript_value);531 assert(subscript_value);
532532
533 if (type_entry->size_in_bits == 0) {
534 return nullptr;
535 }
536
533 if (type_entry->id == TypeTableEntryIdArray) {537 if (type_entry->id == TypeTableEntryIdArray) {
534 LLVMValueRef indices[] = {538 LLVMValueRef indices[] = {
535 LLVMConstNull(g->builtin_types.entry_usize->type_ref),539 LLVMConstNull(g->builtin_types.entry_usize->type_ref),
...@@ -670,7 +674,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva...@@ -670,7 +674,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva
670674
671 LLVMValueRef ptr = gen_array_ptr(g, node);675 LLVMValueRef ptr = gen_array_ptr(g, node);
672676
673 if (is_lvalue) {677 if (is_lvalue || !ptr) {
674 return ptr;678 return ptr;
675 } else {679 } else {
676 add_debug_source_node(g, node);680 add_debug_source_node(g, node);
...@@ -1189,6 +1193,10 @@ static LLVMValueRef gen_assign_expr(CodeGen *g, AstNode *node) {...@@ -1189,6 +1193,10 @@ static LLVMValueRef gen_assign_expr(CodeGen *g, AstNode *node) {
11891193
1190 LLVMValueRef value = gen_expr(g, node->data.bin_op_expr.op2);1194 LLVMValueRef value = gen_expr(g, node->data.bin_op_expr.op2);
11911195
1196 if (op1_type->size_in_bits == 0) {
1197 return nullptr;
1198 }
1199
1192 return gen_assign_raw(g, node, node->data.bin_op_expr.bin_op, target_ref, value, op1_type, op2_type);1200 return gen_assign_raw(g, node, node->data.bin_op_expr.bin_op, target_ref, value, op1_type, op2_type);
1193}1201}
11941202
...@@ -1723,7 +1731,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa...@@ -1723,7 +1731,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
1723 if (var_decl->expr) {1731 if (var_decl->expr) {
1724 *init_value = gen_expr(g, var_decl->expr);1732 *init_value = gen_expr(g, var_decl->expr);
1725 }1733 }
1726 if (variable->type->id == TypeTableEntryIdVoid) {1734 if (variable->type->size_in_bits == 0) {
1727 return nullptr;1735 return nullptr;
1728 } else {1736 } else {
1729 if (var_decl->expr) {1737 if (var_decl->expr) {
...@@ -1788,7 +1796,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {...@@ -1788,7 +1796,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {
1788 get_resolved_expr(node)->block_context,1796 get_resolved_expr(node)->block_context,
1789 &node->data.symbol_expr.symbol);1797 &node->data.symbol_expr.symbol);
1790 assert(variable);1798 assert(variable);
1791 if (variable->type->id == TypeTableEntryIdVoid) {1799 if (variable->type->size_in_bits == 0) {
1792 return nullptr;1800 return nullptr;
1793 } else if (variable->is_ptr) {1801 } else if (variable->is_ptr) {
1794 assert(variable->value_ref);1802 assert(variable->value_ref);
...@@ -2122,8 +2130,9 @@ static void do_code_gen(CodeGen *g) {...@@ -2122,8 +2130,9 @@ static void do_code_gen(CodeGen *g) {
2122 break;2130 break;
21232131
2124 VariableTableEntry *var = entry->value;2132 VariableTableEntry *var = entry->value;
2125 if (var->type->id == TypeTableEntryIdVoid)2133 if (var->type->size_in_bits == 0) {
2126 continue;2134 continue;
2135 }
21272136
2128 unsigned tag;2137 unsigned tag;
2129 unsigned arg_no;2138 unsigned arg_no;
...@@ -2732,7 +2741,9 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou...@@ -2732,7 +2741,9 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou
2732 g->bootstrap_import = add_special_code(g, "bootstrap.zig");2741 g->bootstrap_import = add_special_code(g, "bootstrap.zig");
2733 }2742 }
27342743
2735 add_special_code(g, "builtin.zig");2744 if (g->out_type == OutTypeExe) {
2745 add_special_code(g, "builtin.zig");
2746 }
2736 }2747 }
27372748
2738 if (g->verbose) {2749 if (g->verbose) {
std/rand.zig+1-1
...@@ -59,7 +59,7 @@ pub struct Rand {...@@ -59,7 +59,7 @@ pub struct Rand {
5959
60 while (true) {60 while (true) {
61 r.get_bytes_aligned(rand_val_array);61 r.get_bytes_aligned(rand_val_array);
62 const rand_val = *((&u64)(rand_val_array.ptr));62 const rand_val = *(&u64)(rand_val_array.ptr);
63 if (rand_val < upper_bound) {63 if (rand_val < upper_bound) {
64 return start + (rand_val % range);64 return start + (rand_val % range);
65 }65 }
test/run_tests.cpp+19
...@@ -351,6 +351,25 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {...@@ -351,6 +351,25 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
351351
352 )SOURCE", "OK\n");352 )SOURCE", "OK\n");
353353
354 add_simple_case("void arrays", R"SOURCE(
355use "std.zig";
356
357pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
358 var array: [4]void;
359 array[0] = void{};
360 array[1] = array[2];
361 if (@sizeof(@typeof(array)) != 0) {
362 print_str("BAD\n");
363 }
364 if (array.len != 4) {
365 print_str("BAD\n");
366 }
367 print_str("OK\n");
368 return 0;
369}
370 )SOURCE", "OK\n");
371
372
354 add_simple_case("mutable local variables", R"SOURCE(373 add_simple_case("mutable local variables", R"SOURCE(
355use "std.zig";374use "std.zig";
356375