Skip to content

Commit 09ee887

Browse files
committed
add behavior test for comptime pointer casting
closes #1150 closes #1292 closes #4093
1 parent aca9c74 commit 09ee887

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/behavior/ptrcast.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
203203
}
204204
}
205205

206+
test "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+
206237
test "implicit optional pointer to optional anyopaque pointer" {
207238
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
208239
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO

0 commit comments

Comments
 (0)