authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-27 12:15:49+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-27 12:15:49+02:00
log1bbca4f9350ffd7ebbfc5c54a307f54d448f5929
treef3094718637cad2daffd4a0a9f3fb623e6591996
parent950d840be66deb9239c0effa90ee41a7c0884f95

stage2: fix bitcast to optional ptr in llvm backend; omit safety check for intToPtr on optional ptr


3 files changed, 11 insertions(+), 5 deletions(-)

lib/std/os/linux.zig+9-3
...@@ -865,13 +865,19 @@ pub fn flock(fd: fd_t, operation: i32) usize {...@@ -865,13 +865,19 @@ pub fn flock(fd: fd_t, operation: i32) usize {
865 return syscall2(.flock, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, operation)));865 return syscall2(.flock, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, operation)));
866}866}
867867
868var vdso_clock_gettime = @ptrCast(?*const anyopaque, init_vdso_clock_gettime);868var vdso_clock_gettime = if (builtin.zig_backend == .stage1)
869 @ptrCast(?*const anyopaque, init_vdso_clock_gettime)
870else
871 @ptrCast(?*const anyopaque, &init_vdso_clock_gettime);
869872
870// We must follow the C calling convention when we call into the VDSO873// We must follow the C calling convention when we call into the VDSO
871const vdso_clock_gettime_ty = fn (i32, *timespec) callconv(.C) usize;874const vdso_clock_gettime_ty = if (builtin.zig_backend == .stage1)
875 fn (i32, *timespec) callconv(.C) usize
876else
877 *const fn (i32, *timespec) callconv(.C) usize;
872878
873pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {879pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
874 if (@hasDecl(VDSO, "CGT_SYM") and builtin.zig_backend == .stage1) {880 if (@hasDecl(VDSO, "CGT_SYM")) {
875 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered);881 const ptr = @atomicLoad(?*const anyopaque, &vdso_clock_gettime, .Unordered);
876 if (ptr) |fn_ptr| {882 if (ptr) |fn_ptr| {
877 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);883 const f = @ptrCast(vdso_clock_gettime_ty, fn_ptr);
src/codegen/llvm.zig+1-1
...@@ -3892,7 +3892,7 @@ pub const FuncGen = struct {...@@ -3892,7 +3892,7 @@ pub const FuncGen = struct {
3892 return self.builder.buildBitCast(operand, llvm_dest_ty.pointerType(0), "");3892 return self.builder.buildBitCast(operand, llvm_dest_ty.pointerType(0), "");
3893 }3893 }
38943894
3895 if (operand_ty.zigTypeTag() == .Int and inst_ty.zigTypeTag() == .Pointer) {3895 if (operand_ty.zigTypeTag() == .Int and inst_ty.isPtrAtRuntime()) {
3896 return self.builder.buildIntToPtr(operand, llvm_dest_ty, "");3896 return self.builder.buildIntToPtr(operand, llvm_dest_ty, "");
3897 }3897 }
38983898
src/type.zig+1-1
...@@ -2602,7 +2602,7 @@ pub const Type = extern union {...@@ -2602,7 +2602,7 @@ pub const Type = extern union {
2602 const payload = self.castTag(.pointer).?.data;2602 const payload = self.castTag(.pointer).?.data;
2603 return payload.@"allowzero";2603 return payload.@"allowzero";
2604 },2604 },
2605 else => false,2605 else => return self.zigTypeTag() == .Optional,
2606 };2606 };
2607 }2607 }
26082608