| author | |
| committer | |
| log | 258bc73eee557ada944c9d25ed85d9baf8035ad7 |
| tree | d34d6cca4d4f91a6938ff27fb5eb55c9b7ce1915 |
| parent | 187d00ca835d2c923cbc0a3ab9e861e82888d403 |
3 files changed, 50 insertions(+), 40 deletions(-)
src/codegen.cpp+3-15| ... | ... | @@ -203,21 +203,6 @@ static LLVMValueRef gen_array_ptr(CodeGen *g, AstNode *node) { |
| 203 | 203 | AstNode *array_expr_node = node->data.array_access_expr.array_ref_expr; |
| 204 | 204 | |
| 205 | 205 | LLVMValueRef array_ptr = gen_expr(g, array_expr_node); |
| 206 | /* | |
| 207 | if (array_expr_node->type == NodeTypeSymbol) { | |
| 208 | VariableTableEntry *var = find_variable(array_expr_node->codegen_node->expr_node.block_context, | |
| 209 | &array_expr_node->data.symbol); | |
| 210 | assert(var); | |
| 211 | ||
| 212 | array_ptr = var->value_ref; | |
| 213 | } else if (array_expr_node->type == NodeTypeFieldAccessExpr) { | |
| 214 | zig_panic("TODO gen array ptr field access expr"); | |
| 215 | } else if (array_expr_node->type == NodeTypeArrayAccessExpr) { | |
| 216 | zig_panic("TODO gen array ptr array access expr"); | |
| 217 | } else { | |
| 218 | array_ptr = gen_expr(g, array_expr_node); | |
| 219 | } | |
| 220 | */ | |
| 221 | 206 | |
| 222 | 207 | LLVMValueRef subscript_value = gen_expr(g, node->data.array_access_expr.subscript); |
| 223 | 208 | |
| ... | ... | @@ -1363,6 +1348,9 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { |
| 1363 | 1348 | |
| 1364 | 1349 | { |
| 1365 | 1350 | TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry; |
| 1351 | if (before_type && before_type->id == TypeTableEntryIdUnreachable) { | |
| 1352 | return val; | |
| 1353 | } | |
| 1366 | 1354 | val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_cast); |
| 1367 | 1355 | } |
| 1368 | 1356 |
std/std.zig+26-25| ... | ... | @@ -19,8 +19,8 @@ fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { |
| 19 | 19 | : "rcx", "r11") |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> isize { | |
| 23 | return syscall3(SYS_getrandom, buf as usize, count, flags as usize) as isize; | |
| 22 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> i32 { | |
| 23 | return syscall3(SYS_getrandom, buf as usize, count, flags as usize) as i32; | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | pub fn write(fd: isize, buf: &const u8, count: usize) -> isize { |
| ... | ... | @@ -32,6 +32,30 @@ pub fn exit(status: i32) -> unreachable { |
| 32 | 32 | unreachable; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | // TODO error handling | |
| 36 | pub fn os_get_random_bytes(buf: &u8, count: usize) -> i32 { | |
| 37 | return getrandom(buf, count, 0); | |
| 38 | } | |
| 39 | ||
| 40 | // TODO error handling | |
| 41 | // TODO handle buffering and flushing (mutex protected) | |
| 42 | pub fn print_str(str: string) -> isize { fprint_str(stdout_fileno, str) } | |
| 43 | ||
| 44 | // TODO error handling | |
| 45 | // TODO handle buffering and flushing (mutex protected) | |
| 46 | pub fn fprint_str(fd: isize, str: string) -> isize { | |
| 47 | return write(fd, str.ptr, str.len); | |
| 48 | } | |
| 49 | ||
| 50 | // TODO handle buffering and flushing (mutex protected) | |
| 51 | // TODO error handling | |
| 52 | pub fn print_u64(x: u64) -> isize { | |
| 53 | // TODO use max_u64_base10_digits instead of hardcoding 20 | |
| 54 | var buf: [u8; 20]; | |
| 55 | const len = buf_print_u64(buf.ptr, x); | |
| 56 | return write(stdout_fileno, buf.ptr, len); | |
| 57 | } | |
| 58 | ||
| 35 | 59 | fn digit_to_char(digit: u64) -> u8 { '0' + (digit as u8) } |
| 36 | 60 | |
| 37 | 61 | const max_u64_base10_digits: usize = 20; |
| ... | ... | @@ -63,26 +87,3 @@ fn buf_print_u64(out_buf: &u8, x: u64) -> usize { |
| 63 | 87 | return len; |
| 64 | 88 | } |
| 65 | 89 | |
| 66 | // TODO error handling | |
| 67 | // TODO handle buffering and flushing (mutex protected) | |
| 68 | pub fn print_str(str: string) -> isize { fprint_str(stdout_fileno, str) } | |
| 69 | ||
| 70 | // TODO error handling | |
| 71 | // TODO handle buffering and flushing (mutex protected) | |
| 72 | pub fn fprint_str(fd: isize, str: string) -> isize { | |
| 73 | return write(fd, str.ptr, str.len); | |
| 74 | } | |
| 75 | ||
| 76 | // TODO handle buffering and flushing (mutex protected) | |
| 77 | // TODO error handling | |
| 78 | pub fn print_u64(x: u64) -> isize { | |
| 79 | // TODO use max_u64_base10_digits instead of hardcoding 20 | |
| 80 | var buf: [u8; 20]; | |
| 81 | const len = buf_print_u64(buf.ptr, x); | |
| 82 | return write(stdout_fileno, buf.ptr, len); | |
| 83 | } | |
| 84 | ||
| 85 | // TODO error handling | |
| 86 | pub fn os_get_random_bytes(buf: &u8, count: usize) -> isize { | |
| 87 | return getrandom(buf, count, 0); | |
| 88 | } |
test/run_tests.cpp+21| ... | ... | @@ -682,6 +682,21 @@ export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 682 | 682 | return 0; |
| 683 | 683 | } |
| 684 | 684 | )SOURCE", "x is true\n"); |
| 685 | ||
| 686 | add_simple_case("implicit cast after unreachable", R"SOURCE( | |
| 687 | use "std.zig"; | |
| 688 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { | |
| 689 | const x = outer(); | |
| 690 | if (x == 1234) { | |
| 691 | print_str("OK\n"); | |
| 692 | } | |
| 693 | return 0; | |
| 694 | } | |
| 695 | fn inner() -> i32 { 1234 } | |
| 696 | fn outer() -> isize { | |
| 697 | return inner(); | |
| 698 | } | |
| 699 | )SOURCE", "OK\n"); | |
| 685 | 700 | } |
| 686 | 701 | |
| 687 | 702 | //////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | @@ -978,6 +993,12 @@ fn f() { |
| 978 | 993 | if (const x ?= true) { } |
| 979 | 994 | } |
| 980 | 995 | )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type"); |
| 996 | ||
| 997 | add_compile_fail_case("cast unreachable", R"SOURCE( | |
| 998 | fn f() -> i32 { | |
| 999 | (return 1) as i32 | |
| 1000 | } | |
| 1001 | )SOURCE", 1, ".tmp_source.zig:3:16: error: invalid cast from type 'unreachable' to 'i32'"); | |
| 981 | 1002 | } |
| 982 | 1003 | |
| 983 | 1004 | static void print_compiler_invocation(TestCase *test_case) { |