aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-18 13:57:17 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-12-18 18:37:12 -0700
commit09ee887e9f08ad1f8124dc57ac3bd2f0df9148b5 (patch)
tree768c692248a1a6d1dc7ac96d12e7c76861c54623
parentaca9c74e80e106309b9783ff251ab0cdd3fb9626 (diff)
downloadzig-09ee887e9f08ad1f8124dc57ac3bd2f0df9148b5.tar.gz
zig-09ee887e9f08ad1f8124dc57ac3bd2f0df9148b5.zip
add behavior test for comptime pointer casting
closes #1150 closes #1292 closes #4093
-rw-r--r--test/behavior/ptrcast.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig
index 982a0b862f..f25161ece8 100644
--- a/test/behavior/ptrcast.zig
+++ b/test/behavior/ptrcast.zig
@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
}
}
+test "ptrcast of const integer has the correct object size" {
+ const is_value = ~@intCast(isize, std.math.minInt(isize));
+ const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
+ if (@sizeOf(isize) == 8) {
+ switch (native_endian) {
+ .Little => {
+ try expect(is_bytes[0] == 0xff);
+ try expect(is_bytes[1] == 0xff);
+ try expect(is_bytes[2] == 0xff);
+ try expect(is_bytes[3] == 0xff);
+
+ try expect(is_bytes[4] == 0xff);
+ try expect(is_bytes[5] == 0xff);
+ try expect(is_bytes[6] == 0xff);
+ try expect(is_bytes[7] == 0x7f);
+ },
+ .Big => {
+ try expect(is_bytes[0] == 0x7f);
+ try expect(is_bytes[1] == 0xff);
+ try expect(is_bytes[2] == 0xff);
+ try expect(is_bytes[3] == 0xff);
+
+ try expect(is_bytes[4] == 0xff);
+ try expect(is_bytes[5] == 0xff);
+ try expect(is_bytes[6] == 0xff);
+ try expect(is_bytes[7] == 0xff);
+ },
+ }
+ }
+}
+
test "implicit optional pointer to optional anyopaque pointer" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO