aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-03-12 23:03:47 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-03-24 18:28:32 -0400
commitb1c07c0ea9e351a43c9bc2fe747fc07c0a19e005 (patch)
tree776d95a9b65f0cf2391bf553e536dbc2f200b127 /src/codegen.cpp
parent2cff31937f6008769ad1034f9451d136d03c06bb (diff)
downloadzig-b1c07c0ea9e351a43c9bc2fe747fc07c0a19e005.tar.gz
zig-b1c07c0ea9e351a43c9bc2fe747fc07c0a19e005.zip
move error ret tracing codegen to zig ir
progress towards #821
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index de8cfa31ed..eddadb94ea 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1607,32 +1607,25 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
return instruction->llvm_value;
}
+static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,
+ IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)
+{
+ assert(g->have_err_ret_tracing);
+
+ LLVMValueRef return_err_fn = get_return_err_fn(g);
+ LLVMValueRef args[] = {
+ g->cur_err_ret_trace_val,
+ };
+ LLVMValueRef call_instruction = ZigLLVMBuildCall(g->builder, return_err_fn, args, 1,
+ get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAuto, "");
+ LLVMSetTailCall(call_instruction, true);
+ return call_instruction;
+}
+
static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) {
LLVMValueRef value = ir_llvm_value(g, return_instruction->value);
TypeTableEntry *return_type = return_instruction->value->value.type;
- if (g->have_err_ret_tracing) {
- bool is_err_return = false;
- if (return_type->id == TypeTableEntryIdErrorUnion) {
- if (return_instruction->value->value.special == ConstValSpecialStatic) {
- is_err_return = return_instruction->value->value.data.x_err_union.err != nullptr;
- } else if (return_instruction->value->value.special == ConstValSpecialRuntime) {
- is_err_return = return_instruction->value->value.data.rh_error_union == RuntimeHintErrorUnionError;
- // TODO: emit a branch to check if the return value is an error
- }
- } else if (return_type->id == TypeTableEntryIdErrorSet) {
- is_err_return = true;
- }
- if (is_err_return) {
- LLVMValueRef return_err_fn = get_return_err_fn(g);
- LLVMValueRef args[] = {
- g->cur_err_ret_trace_val,
- };
- LLVMValueRef call_instruction = ZigLLVMBuildCall(g->builder, return_err_fn, args, 1,
- get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_FnInlineAuto, "");
- LLVMSetTailCall(call_instruction, true);
- }
- }
if (handle_is_ptr(return_type)) {
if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) {
assert(g->cur_ret_ptr);
@@ -4400,6 +4393,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
return ir_render_coro_alloc_helper(g, executable, (IrInstructionCoroAllocHelper *)instruction);
case IrInstructionIdAtomicRmw:
return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);
+ case IrInstructionIdSaveErrRetAddr:
+ return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);
}
zig_unreachable();
}