Sema: fix empty struct init

* Extract common logic between `zirStructInitEmpty` and
   `zirStructInit`.
 * `resolveTypeFields` additionally sets status to `have_layout` if the
   total number of fields is 0.
This commit is contained in:
Andrew Kelley
2021-12-21 20:34:27 -07:00
parent 06d751dbb3
commit 88be5bd81d
4 changed files with 94 additions and 60 deletions

View File

@@ -1487,7 +1487,6 @@ pub const DeclGen = struct {
return self.context.constStruct(&fields, fields.len, .False);
}
const llvm_type = try self.llvmType(tv.ty);
if (!tv.ty.childType().hasCodeGenBits() or !decl.ty.hasCodeGenBits()) {
return self.lowerPtrToVoid(tv.ty);
}
@@ -1498,6 +1497,8 @@ pub const DeclGen = struct {
try self.resolveLlvmFunction(decl)
else
try self.resolveGlobalDecl(decl);
const llvm_type = try self.llvmType(tv.ty);
return llvm_val.constBitCast(llvm_type);
}