aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-05-31 01:36:57 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-05-31 01:36:57 -0400
commitccce3d852681bfe60bce92a6766b4f431dd73571 (patch)
tree521bf62dffb4d1c95be881a6c8c3d7208124c2eb /src/ir.cpp
parent461382ae941e235ad75a6b3d00e05e5369baa98a (diff)
downloadzig-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/ir.cpp')
-rw-r--r--src/ir.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index f700404f29..3420a85fce 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -1382,6 +1382,9 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in
FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack,
ResultLoc *result_loc, ZigType *return_type)
{
+ // must be resolved before building the call instruction
+ IrInstruction *resolved_result_loc = ir_resolve_result(ira, result_loc, return_type, nullptr);
+
IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
source_instruction->scope, source_instruction->source_node);
call_instruction->base.value.type = return_type;
@@ -1393,7 +1396,7 @@ static IrInstruction *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_in
call_instruction->is_async = is_async;
call_instruction->async_allocator = async_allocator;
call_instruction->new_stack = new_stack;
- call_instruction->result_loc = ir_resolve_result(ira, result_loc, return_type, nullptr);
+ call_instruction->result_loc = resolved_result_loc;
if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);
for (size_t i = 0; i < arg_count; i += 1)
@@ -14347,10 +14350,14 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, ResultLoc *result_lo
}
// give nullptr for value to resolve it at runtime
-// returns a result location, or nullptr if the result location was already taken care of by this function
+// returns a result location, or nullptr if the result location was already taken care of
static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, ZigType *value_type,
IrInstruction *value)
{
+ if (result_loc->implicit_elem_type != nullptr) {
+ // already resolved
+ return nullptr;
+ }
result_loc->gen_instruction = value;
result_loc->implicit_elem_type = value_type;
switch (result_loc->id) {