master
1const std = @import("std");
2const expect = std.testing.expect;
3const expectEqualSlices = std.testing.expectEqualSlices;
4const expectEqualStrings = std.testing.expectEqualStrings;
5const mem = std.mem;
6const builtin = @import("builtin");
7
8// can't really run this test but we can make sure it has no compile error
9// and generates code
10const vram = @as([*]volatile u8, @ptrFromInt(0x20000000))[0..0x8000];
11export fn writeToVRam() void {
12 if (builtin.zig_backend == .stage2_riscv64) return;
13
14 vram[0] = 'X';
15}
16
17const PackedStruct = packed struct {
18 a: u8,
19 b: u8,
20};
21const PackedUnion = packed union {
22 a: packed struct(u32) {
23 a: u8,
24 b: u24 = 0,
25 },
26 b: u32,
27};
28
29test "packed struct, enum, union parameters in extern function" {
30 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
31
32 testPackedStuff(&(PackedStruct{
33 .a = 1,
34 .b = 2,
35 }), &(PackedUnion{ .a = .{ .a = 1 } }));
36}
37
38export fn testPackedStuff(a: *const PackedStruct, b: *const PackedUnion) void {
39 if (false) {
40 a;
41 b;
42 }
43}
44
45test "export function alias" {
46 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
47
48 _ = struct {
49 fn foo_internal() callconv(.c) u32 {
50 return 123;
51 }
52 export const foo_exported = foo_internal;
53 };
54 const Import = struct {
55 extern fn foo_exported() u32;
56 };
57 try expect(Import.foo_exported() == 123);
58}