diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-05-31 01:36:57 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-05-31 01:36:57 -0400 |
| commit | ccce3d852681bfe60bce92a6766b4f431dd73571 (patch) | |
| tree | 521bf62dffb4d1c95be881a6c8c3d7208124c2eb /src/codegen.cpp | |
| parent | 461382ae941e235ad75a6b3d00e05e5369baa98a (diff) | |
| download | zig-ccce3d852681bfe60bce92a6766b4f431dd73571.tar.gz zig-ccce3d852681bfe60bce92a6766b4f431dd73571.zip | |
no-copy semantics for function forwarding
```zig
fn foo() Foo {
return bar();
}
```
```llvm
define internal fastcc void @foo(%Foo* nonnull sret) unnamed_addr #2 !dbg !48 {
Entry:
call fastcc void @bar(%Foo* sret %0), !dbg !52
ret void, !dbg !54
}
```
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index ccbf911686..d468b60183 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1995,7 +1995,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { if (!type_has_bits(instruction->value.type)) return nullptr; if (!instruction->llvm_value) { - assert(instruction->value.special != ConstValSpecialRuntime); + src_assert(instruction->value.special != ConstValSpecialRuntime, instruction->source_node); assert(instruction->value.type); render_const_val(g, &instruction->value, ""); // we might have to do some pointer casting here due to the way union @@ -2388,7 +2388,11 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) { assert(g->cur_ret_ptr); - gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value); + if (return_instruction->value->value.special != ConstValSpecialRuntime) { + // if it's comptime we have to do this but if it's runtime trust that + // result location mechanism took care of it. + gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value); + } LLVMBuildRetVoid(g->builder); } else if (handle_is_ptr(return_type)) { LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, ""); |
