authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-18 13:57:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-18 18:37:12-07:00
log09ee887e9f08ad1f8124dc57ac3bd2f0df9148b5
tree768c692248a1a6d1dc7ac96d12e7c76861c54623
parentaca9c74e80e106309b9783ff251ab0cdd3fb9626

add behavior test for comptime pointer casting

closes #1150 closes #1292 closes #4093

1 files changed, 31 insertions(+), 0 deletions(-)

test/behavior/ptrcast.zig+31
...@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {...@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
203 }203 }
204}204}
205205
206test "ptrcast of const integer has the correct object size" {
207 const is_value = ~@intCast(isize, std.math.minInt(isize));
208 const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
209 if (@sizeOf(isize) == 8) {
210 switch (native_endian) {
211 .Little => {
212 try expect(is_bytes[0] == 0xff);
213 try expect(is_bytes[1] == 0xff);
214 try expect(is_bytes[2] == 0xff);
215 try expect(is_bytes[3] == 0xff);
216
217 try expect(is_bytes[4] == 0xff);
218 try expect(is_bytes[5] == 0xff);
219 try expect(is_bytes[6] == 0xff);
220 try expect(is_bytes[7] == 0x7f);
221 },
222 .Big => {
223 try expect(is_bytes[0] == 0x7f);
224 try expect(is_bytes[1] == 0xff);
225 try expect(is_bytes[2] == 0xff);
226 try expect(is_bytes[3] == 0xff);
227
228 try expect(is_bytes[4] == 0xff);
229 try expect(is_bytes[5] == 0xff);
230 try expect(is_bytes[6] == 0xff);
231 try expect(is_bytes[7] == 0xff);
232 },
233 }
234 }
235}
236
206test "implicit optional pointer to optional anyopaque pointer" {237test "implicit optional pointer to optional anyopaque pointer" {
207 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO238 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
208 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO239 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO