Skip to content

Commit 480d528

Browse files
authored
[CIR][NFC] Fix build warning in getCIRSourceLanguage (llvm#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.
1 parent 0d6ca2f commit 480d528

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext,
103103
PtrDiffTy =
104104
cir::IntType::get(&getMLIRContext(), sizeTypeSize, /*isSigned=*/true);
105105

106-
theModule->setAttr(
107-
cir::CIRDialect::getSourceLanguageAttrName(),
108-
cir::SourceLanguageAttr::get(&mlirContext, getCIRSourceLanguage()));
106+
std::optional<cir::SourceLanguage> sourceLanguage = getCIRSourceLanguage();
107+
if (sourceLanguage)
108+
theModule->setAttr(
109+
cir::CIRDialect::getSourceLanguageAttrName(),
110+
cir::SourceLanguageAttr::get(&mlirContext, *sourceLanguage));
109111
theModule->setAttr(cir::CIRDialect::getTripleAttrName(),
110112
builder.getStringAttr(getTriple().str()));
111113

@@ -513,7 +515,7 @@ void CIRGenModule::setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op) {
513515
assert(!cir::MissingFeatures::setTargetAttributes());
514516
}
515517

516-
cir::SourceLanguage CIRGenModule::getCIRSourceLanguage() const {
518+
std::optional<cir::SourceLanguage> CIRGenModule::getCIRSourceLanguage() const {
517519
using ClangStd = clang::LangStandard;
518520
using CIRLang = cir::SourceLanguage;
519521
auto opts = getLangOpts();
@@ -528,6 +530,7 @@ cir::SourceLanguage CIRGenModule::getCIRSourceLanguage() const {
528530
// TODO(cir): support remaining source languages.
529531
assert(!cir::MissingFeatures::sourceLanguageCases());
530532
errorNYI("CIR does not yet support the given source language");
533+
return std::nullopt;
531534
}
532535

533536
static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd) {

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class CIRGenModule : public CIRGenTypeCache {
480480
void setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op);
481481

482482
/// Map source language used to a CIR attribute.
483-
cir::SourceLanguage getCIRSourceLanguage() const;
483+
std::optional<cir::SourceLanguage> getCIRSourceLanguage() const;
484484
};
485485
} // namespace CIRGen
486486

0 commit comments

Comments
 (0)