aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2024-01-29 14:33:53 +0200
committerAndrew Kelley <andrew@ziglang.org>2024-01-29 17:35:07 -0800
commit7d75c3d3b80c86bbd47e60f85a98e8decc52c611 (patch)
treec52ddac06bfb3495f19e426020c5a693d3f8f480 /test/behavior
parent4dfca01de4fda9a195048011b3339686dce4e936 (diff)
downloadzig-7d75c3d3b80c86bbd47e60f85a98e8decc52c611.tar.gz
zig-7d75c3d3b80c86bbd47e60f85a98e8decc52c611.zip
llvm: ensure returned undef is 0xaa bytes when runtime safety is enabled
Closes #13178
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/undefined.zig22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/behavior/undefined.zig b/test/behavior/undefined.zig
index b26002e080..a093ce669e 100644
--- a/test/behavior/undefined.zig
+++ b/test/behavior/undefined.zig
@@ -97,3 +97,25 @@ test "reslice of undefined global var slice" {
const x = buf[0..1];
try @import("std").testing.expect(x.len == 1 and x[0] == 0);
}
+
+test "returned undef is 0xaa bytes when runtime safety is enabled" {
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+
+ const Rect = struct {
+ x: f32,
+ fn getUndefStruct() @This() {
+ @setRuntimeSafety(true);
+ return undefined;
+ }
+ fn getUndefInt() u32 {
+ @setRuntimeSafety(true);
+ return undefined;
+ }
+ };
+ try std.testing.expect(@as(u32, @bitCast(Rect.getUndefStruct().x)) == 0xAAAAAAAA);
+ try std.testing.expect(Rect.getUndefInt() == 0xAAAAAAAA);
+}