mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-14 02:06:16 +01:00
ir: Various fixes for comptime ptr handling
* Correctly fold ptrToInt on optional types * Generate null as ConstPtrSpecialNull in intToPtr * Correctly stop ptrToInt on ?*T where T is zero-sized Closes #4535
This commit is contained in:
parent
89812217b4
commit
55ea855e2c
3 changed files with 42 additions and 7 deletions
|
|
@ -3,6 +3,15 @@ const builtin = @import("builtin");
|
|||
const Target = @import("std").Target;
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.addTest("@ptrToInt with pointer to zero-sized type",
|
||||
\\export fn entry() void {
|
||||
\\ var pointer: ?*u0 = null;
|
||||
\\ var x = @ptrToInt(pointer);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:3:23: error: pointer to size 0 type has no address",
|
||||
});
|
||||
|
||||
cases.addTest("slice to pointer conversion mismatch",
|
||||
\\pub fn bytesAsSlice(bytes: var) [*]align(1) const u16 {
|
||||
\\ return @ptrCast([*]align(1) const u16, bytes.ptr)[0..1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue