aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-09-16 21:03:55 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-09-16 21:03:55 -0700
commitdbe9a5114e2d56f847b674539ffa0d28fc57ea78 (patch)
tree078fe7aadd48de9c78aea90d6a383ba134622be5 /test
parentdc9d76b630e0fe9a465cec67dc4dc66e8cce7c58 (diff)
downloadzig-dbe9a5114e2d56f847b674539ffa0d28fc57ea78.tar.gz
zig-dbe9a5114e2d56f847b674539ffa0d28fc57ea78.zip
stage2: implement `@setAlignStack` and 128-bit cmpxchg
* test runner is improved to respect `error.SkipZigTest` * start code is improved to `@setAlignStack(16)` before calling main() * the newly passing behavior test has a workaround for the fact that stage2 cannot yet call `std.Target.x86.featureSetHas()` at comptime. This is blocking on comptime closures. The workaround is that there is a new decl `@import("builtin").stage2_x86_cx16` which is a `bool`. * Implement `@setAlignStack`. This language feature should be re-evaluated at some point - I'll file an issue for it. * LLVM backend: apply/remove the cold attribute and noinline attribute where appropriate. * LLVM backend: loads and stores are properly annotated with alignment and volatile attributes. * LLVM backend: allocas are properly annotated with alignment. * Type: fix integers reporting wrong alignment for 256-bit integers and beyond. Once you get to 16 byte aligned, there is no further alignment for larger integers.
Diffstat (limited to 'test')
-rw-r--r--test/behavior/atomics.zig30
-rw-r--r--test/behavior/atomics_stage1.zig25
-rw-r--r--test/cases.zig2
-rw-r--r--test/stage2/darwin.zig4
4 files changed, 33 insertions, 28 deletions
diff --git a/test/behavior/atomics.zig b/test/behavior/atomics.zig
index 51cafdf564..aae187739b 100644
--- a/test/behavior/atomics.zig
+++ b/test/behavior/atomics.zig
@@ -81,3 +81,33 @@ test "cmpxchg with ignored result" {
try expect(5678 == x);
}
+
+test "128-bit cmpxchg" {
+ try test_u128_cmpxchg();
+ comptime try test_u128_cmpxchg();
+}
+
+fn test_u128_cmpxchg() !void {
+ if (builtin.zig_is_stage2) {
+ if (builtin.stage2_arch != .x86_64) return error.SkipZigTest;
+ if (!builtin.stage2_x86_cx16) return error.SkipZigTest;
+ } else {
+ if (builtin.cpu.arch != .x86_64) return error.SkipZigTest;
+ if (comptime !std.Target.x86.featureSetHas(builtin.cpu.features, .cx16)) return error.SkipZigTest;
+ }
+
+ var x: u128 = 1234;
+ if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
+ try expect(x1 == 1234);
+ } else {
+ @panic("cmpxchg should have failed");
+ }
+
+ while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
+ try expect(x1 == 1234);
+ }
+ try expect(x == 5678);
+
+ try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
+ try expect(x == 42);
+}
diff --git a/test/behavior/atomics_stage1.zig b/test/behavior/atomics_stage1.zig
index 8c77ea75b2..c9e0ea1a60 100644
--- a/test/behavior/atomics_stage1.zig
+++ b/test/behavior/atomics_stage1.zig
@@ -3,31 +3,6 @@ const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
const builtin = @import("builtin");
-test "128-bit cmpxchg" {
- try test_u128_cmpxchg();
- comptime try test_u128_cmpxchg();
-}
-
-fn test_u128_cmpxchg() !void {
- if (std.Target.current.cpu.arch != .x86_64) return error.SkipZigTest;
- if (comptime !std.Target.x86.featureSetHas(std.Target.current.cpu.features, .cx16)) return error.SkipZigTest;
-
- var x: u128 = 1234;
- if (@cmpxchgWeak(u128, &x, 99, 5678, .SeqCst, .SeqCst)) |x1| {
- try expect(x1 == 1234);
- } else {
- @panic("cmpxchg should have failed");
- }
-
- while (@cmpxchgWeak(u128, &x, 1234, 5678, .SeqCst, .SeqCst)) |x1| {
- try expect(x1 == 1234);
- }
- try expect(x == 5678);
-
- try expect(@cmpxchgStrong(u128, &x, 5678, 42, .SeqCst, .SeqCst) == null);
- try expect(x == 42);
-}
-
var a_global_variable = @as(u32, 1234);
test "cmpxchg on a global variable" {
diff --git a/test/cases.zig b/test/cases.zig
index 64fe39e07b..59f0ef7146 100644
--- a/test/cases.zig
+++ b/test/cases.zig
@@ -26,7 +26,7 @@ pub fn addCases(ctx: *TestContext) !void {
var case = ctx.exe("hello world with updates", linux_x64);
case.addError("", &[_][]const u8{
- ":90:9: error: struct 'tmp.tmp' has no member named 'main'",
+ ":95:9: error: struct 'tmp.tmp' has no member named 'main'",
});
// Incorrect return type
diff --git a/test/stage2/darwin.zig b/test/stage2/darwin.zig
index 86c2d313a0..959313f021 100644
--- a/test/stage2/darwin.zig
+++ b/test/stage2/darwin.zig
@@ -12,9 +12,9 @@ pub fn addCases(ctx: *TestContext) !void {
.os_tag = .macos,
};
{
- var case = ctx.exe("hello world with updates", target);
+ var case = ctx.exe("darwin hello world with updates", target);
case.addError("", &[_][]const u8{
- ":90:9: error: struct 'tmp.tmp' has no member named 'main'",
+ ":95:9: error: struct 'tmp.tmp' has no member named 'main'",
});
// Incorrect return type