authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-23 03:14:22-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-23 03:14:22-04:00
log0f633167c5228e2f042775354376cdfa54c84879
treea5aee9996b2b04bdaa4a26e0a9f810472a23da0b
parentad9040443cc35b7c250015a272a121a93244db31

fix crash when unwrapping error with no error decls

closes #339

4 files changed, 18 insertions(+), 2 deletions(-)

src/codegen.cpp+2-2
......@@ -668,6 +668,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
668668
669669 g->generate_error_name_table = true;
670670 generate_error_name_table(g);
671 assert(g->err_name_table != nullptr);
671672
672673 size_t unwrap_err_msg_text_len = strlen(unwrap_err_msg_text);
673674 size_t err_buf_len = strlen(unwrap_err_msg_text) + g->largest_err_name_len;
......@@ -755,7 +756,6 @@ static void gen_debug_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val) {
755756 LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);
756757 LLVMBuildCall(g->builder, safety_crash_err_fn, &err_val, 1, "");
757758 LLVMBuildUnreachable(g->builder);
758
759759}
760760
761761static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
......@@ -2649,7 +2649,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
26492649 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
26502650 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile);
26512651
2652 if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on) {
2652 if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on && g->error_decls.length > 1) {
26532653 LLVMValueRef err_val;
26542654 if (type_has_bits(child_type)) {
26552655 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
test/build_examples.zig+1
......@@ -7,4 +7,5 @@ pub fn addCases(cases: &tests.BuildExamplesContext) {
77 cases.add("example/guess_number/main.zig");
88 cases.addBuildFile("example/shared_library/build.zig");
99 cases.addBuildFile("example/mix_o_files/build.zig");
10 cases.addBuildFile("test/standalone/issue_339/build.zig");
1011}
test/standalone/issue_339/build.zig created+8
......@@ -0,0 +1,8 @@
1const Builder = @import("std").build.Builder;
2
3pub fn build(b: &Builder) {
4 const obj = b.addObject("test", "test.zig");
5
6 const test_step = b.step("test", "Test the program");
7 test_step.dependOn(&obj.step);
8}
test/standalone/issue_339/test.zig created+7
......@@ -0,0 +1,7 @@
1pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }
2
3fn bar() -> %void {}
4
5export fn foo() {
6 %%bar();
7}