Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Aug 19, 2021
1 parent ad75852 commit b9bb06d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/behavior.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ test {
_ = @import("behavior/bugs/7047.zig");
_ = @import("behavior/bugs/7003.zig");
_ = @import("behavior/bugs/7250.zig");
_ = @import("behavior/bugs/9584.zig");
_ = @import("behavior/bugs/394.zig");
_ = @import("behavior/bugs/421.zig");
_ = @import("behavior/bugs/529.zig");
Expand Down
60 changes: 60 additions & 0 deletions test/behavior/bugs/9584.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const std = @import("std");

const A = packed struct {
a: bool,
b: bool,
c: bool,
d: bool,

e: bool,
f: bool,
g: bool,
h: bool,
};

const X = union {
x: A,
y: u64,
};

pub fn a(
x0: i32,
x1: i32,
x2: i32,
x3: i32,
x4: i32,
flag_a: bool,
flag_b: bool,
) !void {
_ = x0;
_ = x1;
_ = x2;
_ = x3;
_ = x4;
_ = flag_a;
// With this bug present, `flag_b` would actually contain the value 17.
// Note: this bug only presents itself on debug mode.
try std.testing.expect(@ptrCast(*const u8, &flag_b).* == 1);
}

pub fn b(x: *X) !void {
try a(0, 1, 2, 3, 4, x.x.a, x.x.b);
}

test "bug 9584" {
var flags = A{
.a = false,
.b = true,
.c = false,
.d = false,

.e = false,
.f = true,
.g = false,
.h = false,
};
var x = X{
.x = flags,
};
try b(&x);
}

0 comments on commit b9bb06d

Please sign in to comment.