aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/error.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-08-25 16:10:36 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-08-25 16:15:48 -0700
commitd2ad8afff4c404f6e1a566cce3fa6e7f768503e5 (patch)
tree28ca64fb5e60cf15fdff8a4c6be921c83b7ce8b1 /test/behavior/error.zig
parent9d231c4991ec1e33c3f4a96e5941848705ef5050 (diff)
downloadzig-d2ad8afff4c404f6e1a566cce3fa6e7f768503e5.tar.gz
zig-d2ad8afff4c404f6e1a566cce3fa6e7f768503e5.zip
LLVM: fix missing alignment on wrapping instructions
Previously, when lowering AIR instructions `wrap_errunion_payload`, `wrap_errunion_err`, and `wrap_optional`, the LLVM backend would create an alloca instruction to store the result, but did not set the alignment on it. This caused UB which went undetected for a long time until we started enabling the stack protector. Closes #12594 Unblocks #12508 Inspires #12634 Tests passed locally: * test-behavior * test-cases
Diffstat (limited to 'test/behavior/error.zig')
-rw-r--r--test/behavior/error.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/behavior/error.zig b/test/behavior/error.zig
index b355c85819..684b01a797 100644
--- a/test/behavior/error.zig
+++ b/test/behavior/error.zig
@@ -796,3 +796,19 @@ test "error union of noreturn used with catch" {
const err = NoReturn.testCatch();
try expect(err == error.OtherFailure);
}
+
+test "alignment of wrapping an error union payload" {
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
+
+ const S = struct {
+ const I = extern struct { x: i128 };
+
+ fn foo() anyerror!I {
+ var i: I = .{ .x = 1234 };
+ return i;
+ }
+ };
+ try expect((S.foo() catch unreachable).x == 1234);
+}