@@ -1890,7 +1890,7 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(
18901890 assert (!cir::MissingFeatures::opFuncUnwindTablesAttr ());
18911891 assert (!cir::MissingFeatures::stackProtector ());
18921892
1893- auto existingInlineKind = f.getInlineKind ();
1893+ std::optional<cir::InlineKind> existingInlineKind = f.getInlineKind ();
18941894 bool isNoInline =
18951895 existingInlineKind && *existingInlineKind == cir::InlineKind::NoInline;
18961896 bool isAlwaysInline = existingInlineKind &&
@@ -1901,9 +1901,9 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(
19011901
19021902 if (!isAlwaysInline &&
19031903 codeGenOpts.getInlining () == CodeGenOptions::OnlyAlwaysInlining) {
1904- // If we don't have a declaration to control inlining, the function isn't
1905- // explicitly marked as alwaysinline for semantic reasons, and inlining is
1906- // disabled, mark the function as noinline .
1904+ // If inlining is disabled and we don't have a declaration to control
1905+ // inlining, mark the function as 'noinline' unless it is explicitly
1906+ // marked as 'alwaysinline' .
19071907 f.setInlineKindAttr (
19081908 cir::InlineAttr::get (&getMLIRContext (), cir::InlineKind::NoInline));
19091909 }
@@ -1925,11 +1925,12 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(
19251925 f.setInlineKindAttr (
19261926 cir::InlineAttr::get (&getMLIRContext (), cir::InlineKind::NoInline));
19271927 } else if (decl->hasAttr <AlwaysInlineAttr>() && !isNoInline) {
1928- // (noinline wins over always_inline, and we can't specify both in IR)
1928+ // Don't override AlwaysInline with NoInline, or vice versa, since we can't
1929+ // specify both in IR.
19291930 f.setInlineKindAttr (
19301931 cir::InlineAttr::get (&getMLIRContext (), cir::InlineKind::AlwaysInline));
19311932 } else if (codeGenOpts.getInlining () == CodeGenOptions::OnlyAlwaysInlining) {
1932- // If we're not inlining, then force everything that isn't always_inline
1933+ // If inlining is disabled, force everything that isn't always_inline
19331934 // to carry an explicit noinline attribute.
19341935 if (!isAlwaysInline) {
19351936 f.setInlineKindAttr (
@@ -1940,6 +1941,9 @@ void CIRGenModule::setCIRFunctionAttributesForDefinition(
19401941 // absence to mark things as noinline.
19411942 // Search function and template pattern redeclarations for inline.
19421943 if (auto *fd = dyn_cast<FunctionDecl>(decl)) {
1944+ // TODO: Share this checkForInline implementation with classic codegen.
1945+ // This logic is likely to change over time, so sharing would help ensure
1946+ // consistency.
19431947 auto checkForInline = [](const FunctionDecl *decl) {
19441948 auto checkRedeclForInline = [](const FunctionDecl *redecl) {
19451949 return redecl->isInlineSpecified ();
0 commit comments