From c6b3d06535f4227541c13fe75da347a485abdb4f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 26 Oct 2021 13:46:27 -0700 Subject: Sema: improved C pointers and casting * C pointer types always have allowzero set to true but they omit the word allowzero when printed. * Implement coercion from C pointers to other pointers. * Implement in-memory coercion for slices and pointer-like optionals. * Make slicing a C pointer drop the allowzero bit. * Value representation for pointer-like optionals is now allowed to use pointer tag values in addition to the `opt_payload` tag. --- src/codegen/llvm.zig | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/codegen/llvm.zig') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index ca9e973354..fd92dec413 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1184,6 +1184,8 @@ pub const DeclGen = struct { if (tv.ty.isPtrLikeOptional()) { if (tv.val.castTag(.opt_payload)) |payload| { return self.genTypedValue(.{ .ty = payload_ty, .val = payload.data }); + } else if (is_pl) { + return self.genTypedValue(.{ .ty = payload_ty, .val = tv.val }); } else { const llvm_ty = try self.llvmType(tv.ty); return llvm_ty.constNull(); -- cgit v1.2.3