[clang] [CIR] Unblock simple C++ structure support (PR #138368)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Sat May 3 08:52:34 PDT 2025
================
@@ -365,10 +365,15 @@ mlir::Attribute ConstantEmitter::tryEmitPrivateForVarInit(const VarDecl &d) {
if (!d.hasLocalStorage()) {
QualType ty = cgm.getASTContext().getBaseElementType(d.getType());
if (ty->isRecordType())
- if (d.getInit() && isa<CXXConstructExpr>(d.getInit())) {
- cgm.errorNYI(d.getInit()->getBeginLoc(),
- "tryEmitPrivateForVarInit CXXConstructExpr");
- return {};
+ if (const CXXConstructExpr *e =
+ dyn_cast_or_null<CXXConstructExpr>(d.getInit())) {
+ const CXXConstructorDecl *cd = e->getConstructor();
+ // FIXME: we should probably model this more closely to C++ than
+ // just emitting a global with zero init (mimic what we do for trivial
+ // assignments and whatnots). Since this is for globals shouldn't
+ // be a problem for the near future.
+ if (cd->isTrivial() && cd->isDefaultConstructor())
+ return cir::ZeroAttr::get(cgm.convertType(d.getType()));
----------------
mmha wrote:
OGCG calls `emitNullConstant` here. We have `CIRGenModule::emitNullConstant` partially implemented. In the incubator `CIRGenModule::emitNullConstant` fails with a NYi if the record type is not zero initializable and IMO that's a reasonable limitation to have for now (instead of silently breaking vtables and default ctors).
https://github.com/llvm/llvm-project/pull/138368
More information about the cfe-commits
mailing list