@@ -5108,6 +5108,26 @@ static LLVMValueRef ir_render_result_optional_payload(CodeGen *g, IrExecutable *
5108
5108
return LLVMBuildStructGEP (g->builder , prev_result_loc, maybe_child_index, " " );
5109
5109
}
5110
5110
5111
+ static LLVMValueRef ir_render_assert_non_error (CodeGen *g, IrExecutable *executable,
5112
+ IrInstructionAssertNonError *instruction)
5113
+ {
5114
+ if (!ir_want_runtime_safety (g, &instruction->base ) || g->errors_by_index .length <= 1 ) {
5115
+ return nullptr ;
5116
+ }
5117
+ LLVMValueRef err_val = ir_llvm_value (g, instruction->err_code );
5118
+ LLVMValueRef zero = LLVMConstNull (g->err_tag_type ->type_ref );
5119
+ LLVMValueRef cond_val = LLVMBuildICmp (g->builder , LLVMIntEQ, err_val, zero, " " );
5120
+ LLVMBasicBlockRef err_block = LLVMAppendBasicBlock (g->cur_fn_val , " UnwrapErrError" );
5121
+ LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock (g->cur_fn_val , " UnwrapErrOk" );
5122
+ LLVMBuildCondBr (g->builder , cond_val, ok_block, err_block);
5123
+
5124
+ LLVMPositionBuilderAtEnd (g->builder , err_block);
5125
+ gen_safety_crash_for_err (g, err_val, instruction->base .scope );
5126
+
5127
+ LLVMPositionBuilderAtEnd (g->builder , ok_block);
5128
+ return nullptr ;
5129
+ }
5130
+
5111
5131
static void set_debug_location (CodeGen *g, IrInstruction *instruction) {
5112
5132
AstNode *source_node = instruction->source_node ;
5113
5133
Scope *scope = instruction->scope ;
@@ -5351,6 +5371,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5351
5371
return ir_render_result_return (g, executable, (IrInstructionResultReturn *)instruction);
5352
5372
case IrInstructionIdResultOptionalPayload:
5353
5373
return ir_render_result_optional_payload (g, executable, (IrInstructionResultOptionalPayload *)instruction);
5374
+ case IrInstructionIdAssertNonError:
5375
+ return ir_render_assert_non_error (g, executable, (IrInstructionAssertNonError *)instruction);
5354
5376
case IrInstructionIdResultErrorUnionPayload:
5355
5377
zig_panic (" TODO" );
5356
5378
case IrInstructionIdResultSliceToBytes:
0 commit comments