@@ -240,7 +240,7 @@ class CIRAttrToValue {
240240 .Case <cir::IntAttr, cir::FPAttr, cir::ConstComplexAttr,
241241 cir::ConstArrayAttr, cir::ConstRecordAttr, cir::ConstVectorAttr,
242242 cir::ConstPtrAttr, cir::GlobalViewAttr, cir::TypeInfoAttr,
243- cir::VTableAttr, cir::ZeroAttr>(
243+ cir::UndefAttr, cir:: VTableAttr, cir::ZeroAttr>(
244244 [&](auto attrT) { return visitCirAttr (attrT); })
245245 .Default ([&](auto attrT) { return mlir::Value (); });
246246 }
@@ -254,6 +254,7 @@ class CIRAttrToValue {
254254 mlir::Value visitCirAttr (cir::ConstVectorAttr attr);
255255 mlir::Value visitCirAttr (cir::GlobalViewAttr attr);
256256 mlir::Value visitCirAttr (cir::TypeInfoAttr attr);
257+ mlir::Value visitCirAttr (cir::UndefAttr attr);
257258 mlir::Value visitCirAttr (cir::VTableAttr attr);
258259 mlir::Value visitCirAttr (cir::ZeroAttr attr);
259260
@@ -591,6 +592,13 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::TypeInfoAttr typeInfoAttr) {
591592 return result;
592593}
593594
595+ // / UndefAttr visitor.
596+ mlir::Value CIRAttrToValue::visitCirAttr (cir::UndefAttr undefAttr) {
597+ mlir::Location loc = parentOp->getLoc ();
598+ return mlir::LLVM::UndefOp::create (
599+ rewriter, loc, converter->convertType (undefAttr.getType ()));
600+ }
601+
594602// VTableAttr visitor.
595603mlir::Value CIRAttrToValue::visitCirAttr (cir::VTableAttr vtableArr) {
596604 mlir::Type llvmTy = converter->convertType (vtableArr.getType ());
@@ -2046,9 +2054,11 @@ CIRToLLVMGlobalOpLowering::matchAndRewriteRegionInitializedGlobal(
20462054 cir::GlobalOp op, mlir::Attribute init,
20472055 mlir::ConversionPatternRewriter &rewriter) const {
20482056 // TODO: Generalize this handling when more types are needed here.
2049- assert ((isa<cir::ConstArrayAttr, cir::ConstRecordAttr, cir::ConstVectorAttr,
2050- cir::ConstPtrAttr, cir::ConstComplexAttr, cir::GlobalViewAttr,
2051- cir::TypeInfoAttr, cir::VTableAttr, cir::ZeroAttr>(init)));
2057+ assert (
2058+ (isa<cir::ConstArrayAttr, cir::ConstRecordAttr, cir::ConstVectorAttr,
2059+ cir::ConstPtrAttr, cir::ConstComplexAttr, cir::GlobalViewAttr,
2060+ cir::TypeInfoAttr, cir::UndefAttr, cir::VTableAttr, cir::ZeroAttr>(
2061+ init)));
20522062
20532063 // TODO(cir): once LLVM's dialect has proper equivalent attributes this
20542064 // should be updated. For now, we use a custom op to initialize globals
@@ -2106,8 +2116,8 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
21062116 } else if (mlir::isa<cir::ConstArrayAttr, cir::ConstVectorAttr,
21072117 cir::ConstRecordAttr, cir::ConstPtrAttr,
21082118 cir::ConstComplexAttr, cir::GlobalViewAttr,
2109- cir::TypeInfoAttr, cir::VTableAttr , cir::ZeroAttr>(
2110- init.value ())) {
2119+ cir::TypeInfoAttr, cir::UndefAttr , cir::VTableAttr,
2120+ cir::ZeroAttr>( init.value ())) {
21112121 // TODO(cir): once LLVM's dialect has proper equivalent attributes this
21122122 // should be updated. For now, we use a custom op to initialize globals
21132123 // to the appropriate value.
0 commit comments