diff options
author | Andy Kaylor <akaylor@nvidia.com> | 2025-08-22 14:57:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-22 14:57:31 -0700 |
commit | 480d528053f635d381a471f613631a4ecae321ca (patch) | |
tree | bcf063af1471272bf0041c331967b7e2654d3c2f /clang/lib/CIR/CodeGen/CIRGenModule.cpp | |
parent | 0d6ca2f969332c76f78105f88b373d5aa1810922 (diff) | |
download | llvm-480d528053f635d381a471f613631a4ecae321ca.zip llvm-480d528053f635d381a471f613631a4ecae321ca.tar.gz llvm-480d528053f635d381a471f613631a4ecae321ca.tar.bz2 |
[CIR][NFC] Fix build warning in getCIRSourceLanguage (#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.
Diffstat (limited to 'clang/lib/CIR/CodeGen/CIRGenModule.cpp')
-rw-r--r-- | clang/lib/CIR/CodeGen/CIRGenModule.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 46bca51..4355451 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) { |