authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-12-24 19:44:52-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-25 20:18:15-05:00
logf5b6019646fe76678c993596130f03116989eb12
tree9b5a112189d53c3f591c0ae33e5dc208e318daf2
parent0c30e006c90db4e6ca77d9054d391340282b96f6

Sema: fix missing struct layout for llvm backend

Closes #14063

2 files changed, 25 insertions(+), 0 deletions(-)

src/Sema.zig+12
......@@ -29743,6 +29743,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
2974329743 const payload_ty = ty.errorUnionPayload();
2974429744 return sema.resolveTypeLayout(payload_ty);
2974529745 },
29746 .Fn => {
29747 const info = ty.fnInfo();
29748 if (info.is_generic) {
29749 // Resolving of generic function types is defeerred to when
29750 // the function is instantiated.
29751 return;
29752 }
29753 for (info.param_types) |param_ty| {
29754 try sema.resolveTypeLayout(param_ty);
29755 }
29756 try sema.resolveTypeLayout(info.return_type);
29757 },
2974629758 else => {},
2974729759 }
2974829760}
test/behavior/struct.zig+13
......@@ -1419,3 +1419,16 @@ test "struct field has a pointer to an aligned version of itself" {
14191419
14201420 try expect(&e == e.next);
14211421}
1422
1423test "struct only referenced from optional parameter/return" {
1424 const S = struct {
1425 fn f(_: ?struct { x: u8 }) void {}
1426 fn g() ?struct { x: u8 } {
1427 return null;
1428 }
1429 };
1430
1431 const fp: *const anyopaque = &S.f;
1432 const gp: *const anyopaque = &S.g;
1433 try expect(fp != gp);
1434}