@@ -172,6 +172,7 @@ REGISTER_ENUM_TYPE(GlobalLinkageKind);
172172REGISTER_ENUM_TYPE (VisibilityKind);
173173REGISTER_ENUM_TYPE (CallingConv);
174174REGISTER_ENUM_TYPE (SideEffect);
175+ REGISTER_ENUM_TYPE (CtorKind);
175176} // namespace
176177
177178// / Parse an enum from the keyword, or default to the provided default value.
@@ -2619,18 +2620,35 @@ ParseResult cir::FuncOp::parse(OpAsmParser &parser, OperationState &state) {
26192620 state.addAttribute (annotationsNameAttr, annotations);
26202621 }
26212622
2622- // Add CXXSpecialMember attribute.
2623- if (mlir::succeeded (parser.parseOptionalKeyword (" cxx_special_member " ))) {
2623+ // Parse CXXSpecialMember attribute
2624+ if (mlir::succeeded (parser.parseOptionalKeyword (" cxx_ctor " ))) {
26242625 if (parser.parseLess ().failed ())
26252626 return failure ();
2626- cir::CXXCtorAttr ctor;
2627- if (auto oa = parser.parseOptionalAttribute (ctor); oa.has_value ())
2628- state.addAttribute (cxxSpecialMemberAttr, ctor);
2629- cir::CXXDtorAttr dtor;
2630- if (auto oa = parser.parseOptionalAttribute (dtor); oa.has_value ())
2631- state.addAttribute (cxxSpecialMemberAttr, dtor);
2627+ mlir::Type type;
2628+ if (parser.parseType (type).failed ())
2629+ return failure ();
2630+ if (parser.parseComma ().failed ())
2631+ return failure ();
2632+ cir::CtorKind ctorKind;
2633+ if (parseCIRKeyword<cir::CtorKind>(parser, ctorKind).failed ())
2634+ return failure ();
2635+ if (parser.parseGreater ().failed ())
2636+ return failure ();
2637+
2638+ state.addAttribute (cxxSpecialMemberAttr,
2639+ cir::CXXCtorAttr::get (type, ctorKind));
2640+ }
2641+
2642+ if (mlir::succeeded (parser.parseOptionalKeyword (" cxx_dtor" ))) {
2643+ if (parser.parseLess ().failed ())
2644+ return failure ();
2645+ mlir::Type type;
2646+ if (parser.parseType (type).failed ())
2647+ return failure ();
26322648 if (parser.parseGreater ().failed ())
26332649 return failure ();
2650+
2651+ state.addAttribute (cxxSpecialMemberAttr, cir::CXXDtorAttr::get (type));
26342652 }
26352653
26362654 // If additional attributes are present, parse them.
@@ -2814,12 +2832,16 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
28142832 }
28152833
28162834 if (getCxxSpecialMember ()) {
2817- p << " cxx_special_member<" ;
2818- if (auto cxxCtor = dyn_cast<cir::CXXCtorAttr>(*getCxxSpecialMember ()))
2819- p.printAttribute (cxxCtor);
2820- if (auto cxxDtor = dyn_cast<cir::CXXDtorAttr>(*getCxxSpecialMember ()))
2821- p.printAttribute (cxxDtor);
2822- p << ' >' ;
2835+ if (auto cxxCtor = dyn_cast<cir::CXXCtorAttr>(*getCxxSpecialMember ())) {
2836+ if (cxxCtor.getCtorKind () != cir::CtorKind::Custom)
2837+ p << " cxx_ctor<" << cxxCtor.getType () << " , " << cxxCtor.getCtorKind ()
2838+ << " >" ;
2839+ } else if (auto cxxDtor =
2840+ dyn_cast<cir::CXXDtorAttr>(*getCxxSpecialMember ())) {
2841+ p << " cxx_dtor<" << cxxDtor.getType () << " >" ;
2842+ } else {
2843+ assert (false && " expected a CXX special member" );
2844+ }
28232845 }
28242846
28252847 function_interface_impl::printFunctionAttributes (
0 commit comments