[clang] [CIR][NFC] Fix build warning in getCIRSourceLanguage (PR #155029)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 22 14:10:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Andy Kaylor (andykaylor)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/155029.diff
2 Files Affected:
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+7-4)
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.h (+1-1)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/155029
More information about the cfe-commits
mailing list