@@ -2229,6 +2229,24 @@ CIRGenModule::createCIRBuiltinFunction(mlir::Location loc, StringRef name,
22292229 return fnOp;
22302230}
22312231
2232+ static cir::CtorKind getCtorKindFromDecl (const CXXConstructorDecl *ctor) {
2233+ if (ctor->isDefaultConstructor ())
2234+ return cir::CtorKind::Default;
2235+ if (ctor->isCopyConstructor ())
2236+ return cir::CtorKind::Copy;
2237+ if (ctor->isMoveConstructor ())
2238+ return cir::CtorKind::Move;
2239+ return cir::CtorKind::Custom;
2240+ }
2241+
2242+ static cir::AssignKind getAssignKindFromDecl (const CXXMethodDecl *method) {
2243+ if (method->isCopyAssignmentOperator ())
2244+ return cir::AssignKind::Copy;
2245+ if (method->isMoveAssignmentOperator ())
2246+ return cir::AssignKind::Move;
2247+ llvm_unreachable (" not a copy or move assignment operator" );
2248+ }
2249+
22322250void CIRGenModule::setCXXSpecialMemberAttr (
22332251 cir::FuncOp funcOp, const clang::FunctionDecl *funcDecl) {
22342252 if (!funcDecl)
@@ -2243,32 +2261,18 @@ void CIRGenModule::setCXXSpecialMemberAttr(
22432261 }
22442262
22452263 if (const auto *ctor = dyn_cast<CXXConstructorDecl>(funcDecl)) {
2246- cir::CtorKind ctorKind = cir::CtorKind::Custom;
2247- if (ctor->isDefaultConstructor ())
2248- ctorKind = cir::CtorKind::Default;
2249- else if (ctor->isCopyConstructor ())
2250- ctorKind = cir::CtorKind::Copy;
2251- else if (ctor->isMoveConstructor ())
2252- ctorKind = cir::CtorKind::Move;
2253-
2264+ cir::CtorKind kind = getCtorKindFromDecl (ctor);
22542265 auto cxxCtor = cir::CXXCtorAttr::get (
22552266 convertType (getASTContext ().getCanonicalTagType (ctor->getParent ())),
2256- ctorKind , ctor->isTrivial ());
2267+ kind , ctor->isTrivial ());
22572268 funcOp.setCxxSpecialMemberAttr (cxxCtor);
22582269 return ;
22592270 }
22602271
22612272 const auto *method = dyn_cast<CXXMethodDecl>(funcDecl);
22622273 if (method && (method->isCopyAssignmentOperator () ||
22632274 method->isMoveAssignmentOperator ())) {
2264- cir::AssignKind assignKind;
2265- if (method->isCopyAssignmentOperator ())
2266- assignKind = cir::AssignKind::Copy;
2267- else if (method->isMoveAssignmentOperator ())
2268- assignKind = cir::AssignKind::Move;
2269- else
2270- llvm_unreachable (" unexpected assignment operator kind" );
2271-
2275+ cir::AssignKind assignKind = getAssignKindFromDecl (method);
22722276 auto cxxAssign = cir::CXXAssignAttr::get (
22732277 convertType (getASTContext ().getCanonicalTagType (method->getParent ())),
22742278 assignKind, method->isTrivial ());
0 commit comments