# no-copy semantics for function call init var and literal · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/461382ae941e235ad75a6b3d00e05e5369baa98a)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 461382ae941e235ad75a6b3d00e05e5369baa98a

Requested commit: 461382ae941e235ad75a6b3d00e05e5369baa98a

Commit: 461382ae941e235ad75a6b3d00e05e5369baa98a

Tree: b449441093bf6c26caa97959c2d449a137b0cc23

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

````
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
}
```

````

## Parents

- [8aba0643a55e4a67c0e7e01c1946900164514f4c](https://git.cafe/gitcafe/zig/commit/8aba0643a55e4a67c0e7e01c1946900164514f4c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/461382ae941e235ad75a6b3d00e05e5369baa98a?format=markdown)
