authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 16:29:46-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-19 16:29:46-04:00
log96931228af745b8e69c138b3b83893dafa166cfe
treeec7233505cf5529a825d66948bcd70d8032dc999
parent974db231a08731f642dbf72d716f669fed2bd2ab
signaturelock-open Commit is signed but in an unrecognized format.

fix comptime test error for empty error set


4 files changed, 35 insertions(+), 14 deletions(-)

src/all_types.hpp+1
......@@ -3085,6 +3085,7 @@ struct IrInstructionAlignOf {
30853085struct IrInstructionTestErrSrc {
30863086 IrInstruction base;
30873087
3088 bool resolve_err_set;
30883089 IrInstruction *base_ptr;
30893090};
30903091
src/codegen.cpp+6
......@@ -4913,6 +4913,9 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
49134913static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,
49144914 IrInstructionUnwrapErrCode *instruction)
49154915{
4916 if (instruction->base.value.special != ConstValSpecialRuntime)
4917 return nullptr;
4918
49164919 ZigType *ptr_type = instruction->err_union_ptr->value.type;
49174920 assert(ptr_type->id == ZigTypeIdPointer);
49184921 ZigType *err_union_type = ptr_type->data.pointer.child_type;
......@@ -4930,6 +4933,9 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
49304933static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,
49314934 IrInstructionUnwrapErrPayload *instruction)
49324935{
4936 if (instruction->base.value.special != ConstValSpecialRuntime)
4937 return nullptr;
4938
49334939 bool want_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base) &&
49344940 g->errors_by_index.length > 1;
49354941 if (!want_safety && !type_has_bits(instruction->base.value.type))
src/ir.cpp+20-6
......@@ -2446,10 +2446,11 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
24462446}
24472447
24482448static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2449 IrInstruction *base_ptr)
2449 IrInstruction *base_ptr, bool resolve_err_set)
24502450{
24512451 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);
24522452 instruction->base_ptr = base_ptr;
2453 instruction->resolve_err_set = resolve_err_set;
24532454
24542455 ir_ref_instruction(base_ptr, irb->current_basic_block);
24552456
......@@ -3593,7 +3594,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
35933594
35943595 IrInstruction *ret_ptr = ir_build_result_ptr(irb, scope, node, &result_loc_ret->base,
35953596 return_value);
3596 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, ret_ptr);
3597 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, ret_ptr, false);
35973598
35983599 bool should_inline = ir_should_inline(irb->exec, scope);
35993600 IrInstruction *is_comptime;
......@@ -3639,7 +3640,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
36393640 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
36403641 if (err_union_ptr == irb->codegen->invalid_instruction)
36413642 return irb->codegen->invalid_instruction;
3642 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr);
3643 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true);
36433644
36443645 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
36453646 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
......@@ -5987,7 +5988,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
59875988 LValPtr, nullptr);
59885989 if (err_val_ptr == irb->codegen->invalid_instruction)
59895990 return err_val_ptr;
5990 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr);
5991 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr, true);
59915992 IrBasicBlock *after_cond_block = irb->current_basic_block;
59925993 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
59935994 IrInstruction *cond_br_inst;
......@@ -6771,7 +6772,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
67716772 return err_val_ptr;
67726773
67736774 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
6774 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr);
6775 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true);
67756776
67766777 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");
67776778 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");
......@@ -7381,7 +7382,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
73817382 if (err_union_ptr == irb->codegen->invalid_instruction)
73827383 return irb->codegen->invalid_instruction;
73837384
7384 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr);
7385 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true);
73857386
73867387 IrInstruction *is_comptime;
73877388 if (ir_should_inline(irb->exec, parent_scope)) {
......@@ -22512,6 +22513,19 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
2251222513 }
2251322514 }
2251422515
22516 if (instruction->resolve_err_set) {
22517 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
22518 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {
22519 return ira->codegen->invalid_instruction;
22520 }
22521 if (!type_is_global_error_set(err_set_type) &&
22522 err_set_type->data.error_set.err_count == 0)
22523 {
22524 assert(err_set_type->data.error_set.infer_fn == nullptr);
22525 return ir_const_bool(ira, &instruction->base, false);
22526 }
22527 }
22528
2251522529 return ir_build_test_err_gen(ira, &instruction->base, value);
2251622530 } else if (type_entry->id == ZigTypeIdErrorSet) {
2251722531 return ir_const_bool(ira, &instruction->base, true);
test/stage1/behavior/error.zig+8-8
......@@ -130,10 +130,10 @@ fn testExplicitErrorSetCast(set1: Set1) void {
130130 expect(y == error.A);
131131}
132132
133//test "comptime test error for empty error set" {
134// testComptimeTestErrorEmptySet(1234);
135// comptime testComptimeTestErrorEmptySet(1234);
136//}
133test "comptime test error for empty error set" {
134 testComptimeTestErrorEmptySet(1234);
135 comptime testComptimeTestErrorEmptySet(1234);
136}
137137
138138const EmptyErrorSet = error{};
139139
......@@ -204,10 +204,10 @@ fn foo2(f: fn () anyerror!void) void {
204204
205205fn bar2() (error{}!void) {}
206206
207//test "error: Zero sized error set returned with value payload crash" {
208// _ = foo3(0) catch {};
209// _ = comptime foo3(0) catch {};
210//}
207test "error: Zero sized error set returned with value payload crash" {
208 _ = foo3(0) catch {};
209 _ = comptime foo3(0) catch {};
210}
211211
212212const Error = error{};
213213fn foo3(b: usize) Error!usize {