https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/155029
The getCIRSourceLanguage wasn't returning a value if the source language was anything other than C or C++. This change updates that function to return a std::optional value and only adds the source language attribute if one was returned. >From 0ff0ff0ff6e6452d4a692ab91f1baf711b49737b Mon Sep 17 00:00:00 2001 From: Andy Kaylor <akay...@nvidia.com> Date: Fri, 22 Aug 2025 14:06:50 -0700 Subject: [PATCH] [CIR][NFC] Fix build warning in getCIRSourceLanguage The getCIRSourceLanguage wasn't returning a value if the source language was anything other than C or C++. This change updates that function to return a std::optional value and only adds the source language attribute if one was returned. --- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 11 +++++++---- clang/lib/CIR/CodeGen/CIRGenModule.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 46bca51767c02..43554519ebd4d 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -103,9 +103,11 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext, PtrDiffTy = cir::IntType::get(&getMLIRContext(), sizeTypeSize, /*isSigned=*/true); - theModule->setAttr( - cir::CIRDialect::getSourceLanguageAttrName(), - cir::SourceLanguageAttr::get(&mlirContext, getCIRSourceLanguage())); + std::optional<cir::SourceLanguage> sourceLanguage = getCIRSourceLanguage(); + if (sourceLanguage) + theModule->setAttr( + cir::CIRDialect::getSourceLanguageAttrName(), + cir::SourceLanguageAttr::get(&mlirContext, *sourceLanguage)); theModule->setAttr(cir::CIRDialect::getTripleAttrName(), builder.getStringAttr(getTriple().str())); @@ -513,7 +515,7 @@ void CIRGenModule::setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op) { assert(!cir::MissingFeatures::setTargetAttributes()); } -cir::SourceLanguage CIRGenModule::getCIRSourceLanguage() const { +std::optional<cir::SourceLanguage> CIRGenModule::getCIRSourceLanguage() const { using ClangStd = clang::LangStandard; using CIRLang = cir::SourceLanguage; auto opts = getLangOpts(); @@ -528,6 +530,7 @@ cir::SourceLanguage CIRGenModule::getCIRSourceLanguage() const { // TODO(cir): support remaining source languages. assert(!cir::MissingFeatures::sourceLanguageCases()); errorNYI("CIR does not yet support the given source language"); + return std::nullopt; } static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd) { diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index d90baa55d0b5c..4f5c7f898af8c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -480,7 +480,7 @@ class CIRGenModule : public CIRGenTypeCache { void setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op); /// Map source language used to a CIR attribute. - cir::SourceLanguage getCIRSourceLanguage() const; + std::optional<cir::SourceLanguage> getCIRSourceLanguage() const; }; } // namespace CIRGen _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits