Sema: fix missing struct layout for llvm backend

Closes #14063
This commit is contained in:
Jacob Young 2022-12-24 19:44:52 -05:00 committed by Andrew Kelley
parent fe6fd0d541
commit 4068fafcc6
2 changed files with 25 additions and 0 deletions

View file

@ -29155,6 +29155,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
const payload_ty = ty.errorUnionPayload(); const payload_ty = ty.errorUnionPayload();
return sema.resolveTypeLayout(payload_ty); return sema.resolveTypeLayout(payload_ty);
}, },
.Fn => {
const info = ty.fnInfo();
if (info.is_generic) {
// Resolving of generic function types is defeerred to when
// the function is instantiated.
return;
}
for (info.param_types) |param_ty| {
try sema.resolveTypeLayout(param_ty);
}
try sema.resolveTypeLayout(info.return_type);
},
else => {}, else => {},
} }
} }

View file

@ -1430,3 +1430,16 @@ test "struct field has a pointer to an aligned version of itself" {
try expect(&e == e.next); try expect(&e == e.next);
} }
test "struct only referenced from optional parameter/return" {
const S = struct {
fn f(_: ?struct { x: u8 }) void {}
fn g() ?struct { x: u8 } {
return null;
}
};
const fp: *const anyopaque = &S.f;
const gp: *const anyopaque = &S.g;
try expect(fp != gp);
}