authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-31 01:08:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-31 01:08:16-04:00
log461382ae941e235ad75a6b3d00e05e5369baa98a
treeb449441093bf6c26caa97959c2d449a137b0cc23
parent8aba0643a55e4a67c0e7e01c1946900164514f4c
signaturelock-open Commit is signed but in an unrecognized format.

no-copy semantics for function call init var and literal

```zig export fn entry() void { var x = foo(); } const Foo = struct { x: i32, }; fn foo() Foo { return Foo{ .x = 1234, }; } ``` ```llvm define void @entry() #2 !dbg !35 { Entry: %x = alloca %Foo, align 4 call fastcc void @foo(%Foo* sret %x), !dbg !45 call void @llvm.dbg.declare(metadata %Foo* %x, metadata !39, metadata !DIExpression()), !dbg !46 ret void, !dbg !47 } define internal fastcc void @foo(%Foo* nonnull sret) unnamed_addr #2 !dbg !48 { Entry: %1 = bitcast %Foo* %0 to i8*, !dbg !52 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 bitcast (%Foo* @0 to i8*), i64 4, i1 false), !dbg !52 ret void, !dbg !52 } ```

1 files changed, 6 insertions(+), 3 deletions(-)

src/ir.cpp+6-3
...@@ -14365,11 +14365,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z...@@ -14365,11 +14365,11 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
14365 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);14365 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);
14366 IrInstructionAllocaSrc *alloca_src =14366 IrInstructionAllocaSrc *alloca_src =
14367 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);14367 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
14368 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&
14369 result_loc_var->var->gen_is_const;
14370 if (alloca_src->base.child == nullptr) {14368 if (alloca_src->base.child == nullptr) {
14371 uint32_t align = 0; // TODO14369 uint32_t align = 0; // TODO
14372 bool force_comptime = false; // TODO14370 bool force_comptime = false; // TODO
14371 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime &&
14372 result_loc_var->var->gen_is_const;
14373 IrInstruction *alloca_gen;14373 IrInstruction *alloca_gen;
14374 if (is_comptime) {14374 if (is_comptime) {
14375 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);14375 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
...@@ -14378,10 +14378,13 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z...@@ -14378,10 +14378,13 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, ResultLoc *result_loc, Z
14378 alloca_src->name_hint, force_comptime);14378 alloca_src->name_hint, force_comptime);
14379 }14379 }
14380 alloca_src->base.child = alloca_gen;14380 alloca_src->base.child = alloca_gen;
14381 return is_comptime ? nullptr : alloca_src->base.child;
14381 }14382 }
14382 return is_comptime ? nullptr : alloca_src->base.child;14383 return nullptr;
14383 }14384 }
14384 case ResultLocIdReturn: {14385 case ResultLocIdReturn: {
14386 bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime;
14387 if (is_comptime) return nullptr;
14385 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);14388 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);
14386 return ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);14389 return ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);
14387 }14390 }