aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
diff options
context:
space:
mode:
authorEmily Bellows <emily.a.bellows@hey.com>2021-11-02 21:23:41 -0400
committerEmily Bellows <emily.a.bellows@hey.com>2021-11-08 14:23:55 -0500
commite3d638a49e09340bc1f779185cab3ad85d7045af (patch)
tree359853c070abc6130f9cb79900573f6add9d74bb /test/behavior/struct.zig
parenta7d215759e93be971ba5e560578e7473655cdd82 (diff)
downloadzig-e3d638a49e09340bc1f779185cab3ad85d7045af.tar.gz
zig-e3d638a49e09340bc1f779185cab3ad85d7045af.zip
C backend: while, struct tests, better undefined global handling
1. Function signatures that return a no member struct return void 2. Undefined var decls don't get a value generated for them 3. Don't generate bitcast code if the result isn't used, since bitcast is a pure function. Right now struct handling code generates some weird unused bitcast AIR, and this optimization side steps that issue.
Diffstat (limited to 'test/behavior/struct.zig')
-rw-r--r--test/behavior/struct.zig94
1 files changed, 0 insertions, 94 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig
index 104fe64b4c..eeaa80ed69 100644
--- a/test/behavior/struct.zig
+++ b/test/behavior/struct.zig
@@ -32,38 +32,6 @@ fn returnEmptyStructInstance() StructWithNoFields {
return empty_global_instance;
}
-const StructFoo = struct {
- a: i32,
- b: bool,
- c: f32,
-};
-test "structs" {
- var foo: StructFoo = undefined;
- @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo));
- foo.a += 1;
- foo.b = foo.a == 1;
- try testFoo(foo);
- testMutation(&foo);
- try expect(foo.c == 100);
-}
-fn testFoo(foo: StructFoo) !void {
- try expect(foo.b);
-}
-fn testMutation(foo: *StructFoo) void {
- foo.c = 100;
-}
-
-test "struct byval assign" {
- var foo1: StructFoo = undefined;
- var foo2: StructFoo = undefined;
-
- foo1.a = 1234;
- foo2.a = 0;
- try expect(foo2.a == 0);
- foo2 = foo1;
- try expect(foo2.a == 1234);
-}
-
const Node = struct {
val: Val,
next: *Node,
@@ -90,65 +58,3 @@ test "call member function directly" {
const result = MemberFnTestFoo.member(instance);
try expect(result == 1234);
}
-
-test "struct point to self" {
- var root: Node = undefined;
- root.val.x = 1;
-
- var node: Node = undefined;
- node.next = &root;
- node.val.x = 2;
-
- root.next = &node;
-
- try expect(node.next.next.next.val.x == 1);
-}
-
-test "void struct fields" {
- const foo = VoidStructFieldsFoo{
- .a = void{},
- .b = 1,
- .c = void{},
- };
- try expect(foo.b == 1);
- try expect(@sizeOf(VoidStructFieldsFoo) == 4);
-}
-const VoidStructFieldsFoo = struct {
- a: void,
- b: i32,
- c: void,
-};
-
-test "member functions" {
- const r = MemberFnRand{ .seed = 1234 };
- try expect(r.getSeed() == 1234);
-}
-const MemberFnRand = struct {
- seed: u32,
- pub fn getSeed(r: *const MemberFnRand) u32 {
- return r.seed;
- }
-};
-
-test "return struct byval from function" {
- const bar = makeBar2(1234, 5678);
- try expect(bar.y == 5678);
-}
-const Bar = struct {
- x: i32,
- y: i32,
-};
-fn makeBar2(x: i32, y: i32) Bar {
- return Bar{
- .x = x,
- .y = y,
- };
-}
-
-test "return empty struct from fn" {
- _ = testReturnEmptyStructFromFn();
-}
-const EmptyStruct2 = struct {};
-fn testReturnEmptyStructFromFn() EmptyStruct2 {
- return EmptyStruct2{};
-}