aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/bugs/10138.zig
blob: 88dc5acde74fe2863011a3de993b24221da0e0eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const std = @import("std");
const builtin = @import("builtin");

test "registers get overwritten when ignoring return" {
    if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
    if (builtin.cpu.arch != .x86_64 or builtin.os.tag != .linux) return error.SkipZigTest;

    const fd = open();
    _ = write(fd, "a", 1);
    _ = close(fd);
}

fn open() usize {
    return 42;
}

fn write(fd: usize, a: [*]const u8, len: usize) usize {
    return syscall4(.WRITE, fd, @ptrToInt(a), len);
}

fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
    _ = n;
    _ = a;
    _ = b;
    _ = c;
    return 23;
}

fn close(fd: usize) usize {
    if (fd != 42)
        unreachable;
    return 0;
}