From 167854c19c8072270187b91314a5481363af4e12 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 10 May 2024 18:08:41 +0300 Subject: [PATCH 1/2] llvm: lower ptr to int constants with correct address spaces Closes #19915 --- src/codegen/llvm.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 291e76f084..2830933929 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -4376,7 +4376,7 @@ pub const Object = struct { .int => try o.builder.castConst( .inttoptr, try o.builder.intConst(try o.lowerType(Type.usize), offset), - .ptr, + try o.lowerType(Type.fromInterned(ptr.ty)), ), .eu_payload => |eu_ptr| try o.lowerPtr( eu_ptr, From f776e70c3967da637d5488b6a8efaa8377680208 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 21 May 2024 19:51:08 +0300 Subject: [PATCH 2/2] llvm: fix lowering of packed structs with optional pointers Closes #20022 --- src/codegen/llvm.zig | 1 + test/behavior/packed-struct.zig | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 2830933929..4502fe1c30 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -3775,6 +3775,7 @@ pub const Object = struct { .float, .enum_tag, => {}, + .opt => {}, // pointer like optional expected else => unreachable, } const bits = ty.bitSize(mod); diff --git a/test/behavior/packed-struct.zig b/test/behavior/packed-struct.zig index 4870cd5984..51a302c945 100644 --- a/test/behavior/packed-struct.zig +++ b/test/behavior/packed-struct.zig @@ -1304,3 +1304,10 @@ test "2-byte packed struct argument in C calling convention" { try S.bar(s); } } + +test "packed struct contains optional pointer" { + const foo: packed struct { + a: ?*@This() = null, + } = .{}; + try expect(foo.a == null); +}