Skip to content

Commit 958d2a8

Browse files
committed
add tests which segfault
1 parent cd2a07f commit 958d2a8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/stage1/behavior/align.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ test "@ptrCast preserves alignment of bigger source" {
167167
expect(@typeOf(ptr) == *align(16) u8);
168168
}
169169

170+
fn give() anyerror!u128 {
171+
return 3;
172+
}
173+
174+
test "return error union with 128-bit integer" {
175+
expect(3 == try give());
176+
}
177+
170178
test "runtime known array index has best alignment possible" {
171179
// take full advantage of over-alignment
172180
var array align(4) = [_]u8{ 1, 2, 3, 4 };
@@ -251,6 +259,29 @@ test "size of extern struct with 128-bit field" {
251259
}
252260
}
253261

262+
const DefaultAligned = struct {
263+
nevermind: u32,
264+
badguy: i128,
265+
};
266+
267+
test "read 128-bit field from default aligned struct in stack memory" {
268+
var default_aligned = DefaultAligned {
269+
.nevermind = 1,
270+
.badguy = 12,
271+
};
272+
expect(12 == default_aligned.badguy);
273+
}
274+
275+
var default_aligned_global = DefaultAligned {
276+
.nevermind = 1,
277+
.badguy = 12,
278+
};
279+
280+
test "read 128-bit field from default aligned struct in global memory" {
281+
282+
expect(12 == default_aligned_global.badguy);
283+
}
284+
254285
test "alignment of extern() void" {
255286
var runtime_nothing = nothing;
256287
const casted1 = @ptrCast(*const u8, runtime_nothing);

0 commit comments

Comments
 (0)