@@ -1670,6 +1670,44 @@ ConstantEmitter::tryEmitAbstractForInitializer(const VarDecl &D) {
1670
1670
return validateAndPopAbstract (C, state);
1671
1671
}
1672
1672
1673
+ // FIXME(cir): both these helpers belong to ABInfoImpl.cpp in OG, but this
1674
+ // file in CIR sits in TargetLowering instead, which won't make sense here since
1675
+ // they are all AST queries, should belong in a shared location with OG helpers.
1676
+ bool isEmptyRecordForLayout (const ASTContext &Context, QualType T);
1677
+ bool isEmptyFieldForLayout (const ASTContext &ctx, const FieldDecl *fd) {
1678
+ if (fd->isZeroLengthBitField ())
1679
+ return true ;
1680
+
1681
+ if (fd->isUnnamedBitField ())
1682
+ return false ;
1683
+
1684
+ return isEmptyRecordForLayout (ctx, fd->getType ());
1685
+ }
1686
+
1687
+ bool isEmptyRecordForLayout (const ASTContext &ctx, QualType t) {
1688
+ const RecordType *rt = t->getAs <RecordType>();
1689
+ if (!rt)
1690
+ return false ;
1691
+
1692
+ const RecordDecl *rd = rt->getDecl ();
1693
+
1694
+ // If this is a C++ record, check the bases first.
1695
+ if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(rd)) {
1696
+ if (CXXRD->isDynamicClass ())
1697
+ return false ;
1698
+
1699
+ for (const auto &I : CXXRD->bases ())
1700
+ if (!isEmptyRecordForLayout (ctx, I.getType ()))
1701
+ return false ;
1702
+ }
1703
+
1704
+ for (const auto *I : rd->fields ())
1705
+ if (!isEmptyFieldForLayout (ctx, I))
1706
+ return false ;
1707
+
1708
+ return true ;
1709
+ }
1710
+
1673
1711
static mlir::TypedAttr emitNullConstant (CIRGenModule &CGM, const RecordDecl *rd,
1674
1712
bool asCompleteObject) {
1675
1713
const CIRGenRecordLayout &layout = CGM.getTypes ().getCIRGenRecordLayout (rd);
@@ -1698,8 +1736,8 @@ static mlir::TypedAttr emitNullConstant(CIRGenModule &CGM, const RecordDecl *rd,
1698
1736
for (const auto *Field : rd->fields ()) {
1699
1737
// Fill in non-bitfields. (Bitfields always use a zero pattern, which we
1700
1738
// will fill in later.)
1701
- if (!Field->isBitField ()) {
1702
- // TODO(cir) check for !isEmptyFieldForLayout(CGM.getContext (), Field))
1739
+ if (!Field->isBitField () &&
1740
+ !isEmptyFieldForLayout (CGM.getASTContext (), Field)) {
1703
1741
llvm_unreachable (" NYI" );
1704
1742
}
1705
1743
0 commit comments