Skip to content

Conversation

@andykaylor
Copy link
Contributor

Previous CIR commits have introduced a few warnings. This change fixes those.

There are still warnings present when building with GCC because GCC warns about virtual functions being hidden in the mlir::OpConversion classes. A separate discussion will be required to decide what should be done about those.

Previous CIR commits have introduced a few warnings. This change fixes those.

There are still warnings present when building with GCC because GCC warns
about virtual functions being hidden in the mlir::OpConversion classes. A
separate discussion will be required to decide what should be done about
those.
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Mar 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-clangir

Author: Andy Kaylor (andykaylor)

Changes

Previous CIR commits have introduced a few warnings. This change fixes those.

There are still warnings present when building with GCC because GCC warns about virtual functions being hidden in the mlir::OpConversion classes. A separate discussion will be required to decide what should be done about those.


Full diff: https://github.com/llvm/llvm-project/pull/129604.diff

4 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenDecl.cpp (+1-1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenFunction.cpp (+5-6)
  • (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+3-3)
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index c34d42eff6966..406026b0b9f27 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -62,7 +62,7 @@ void CIRGenFunction::emitAutoVarInit(const clang::VarDecl &d) {
 
 void CIRGenFunction::emitAutoVarCleanups(const clang::VarDecl &d) {
   // Check the type for a cleanup.
-  if (QualType::DestructionKind dtorKind = d.needsDestruction(getContext()))
+  if (d.needsDestruction(getContext()))
     cgm.errorNYI(d.getSourceRange(), "emitAutoVarCleanups: type cleanup");
 
   assert(!cir::MissingFeatures::opAllocaPreciseLifetime());
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 90a2fd2a5d806..96ac292f49ef5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -98,6 +98,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
 
     cgf.getCIRGenModule().errorNYI(loc,
                                    "emitScalarConversion for unequal types");
+    return {};
   }
 };
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index 7861a48c93244..ad7560d83fb68 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -13,6 +13,7 @@
 #include "CIRGenFunction.h"
 
 #include "CIRGenCall.h"
+#include "CIRGenValue.h"
 #include "mlir/IR/Location.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/CIR/MissingFeatures.h"
@@ -134,10 +135,9 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, mlir::Location rhs) {
   return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
 }
 
-mlir::LogicalResult CIRGenFunction::declare(mlir::Value addrVal,
-                                            const Decl *var, QualType ty,
-                                            mlir::Location loc,
-                                            CharUnits alignment, bool isParam) {
+void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
+                             mlir::Location loc, CharUnits alignment,
+                             bool isParam) {
   const auto *namedVar = dyn_cast_or_null<NamedDecl>(var);
   assert(namedVar && "Needs a named decl");
   assert(!cir::MissingFeatures::cgfSymbolTable());
@@ -147,8 +147,6 @@ mlir::LogicalResult CIRGenFunction::declare(mlir::Value addrVal,
     allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
   if (ty->isReferenceType() || ty.isConstQualified())
     allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
-
-  return mlir::success();
 }
 
 void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType,
@@ -306,6 +304,7 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
     getCIRGenModule().errorNYI(e->getSourceRange(),
                                std::string("l-value not implemented for '") +
                                    e->getStmtClassName() + "'");
+    return LValue();
     break;
   case Expr::DeclRefExprClass:
     return emitDeclRefLValue(cast<DeclRefExpr>(e));
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 6b383378ae764..cf896d3c0a946 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -97,9 +97,9 @@ class CIRGenFunction : public CIRGenTypeCache {
 private:
   /// Declare a variable in the current scope, return success if the variable
   /// wasn't declared yet.
-  mlir::LogicalResult declare(mlir::Value addrVal, const clang::Decl *var,
-                              clang::QualType ty, mlir::Location loc,
-                              clang::CharUnits alignment, bool isParam = false);
+  void declare(mlir::Value addrVal, const clang::Decl *var, clang::QualType ty,
+               mlir::Location loc, clang::CharUnits alignment,
+               bool isParam = false);
 
 public:
   mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,

@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)

Changes

Previous CIR commits have introduced a few warnings. This change fixes those.

There are still warnings present when building with GCC because GCC warns about virtual functions being hidden in the mlir::OpConversion classes. A separate discussion will be required to decide what should be done about those.


Full diff: https://github.com/llvm/llvm-project/pull/129604.diff

4 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenDecl.cpp (+1-1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenFunction.cpp (+5-6)
  • (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+3-3)
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index c34d42eff6966..406026b0b9f27 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -62,7 +62,7 @@ void CIRGenFunction::emitAutoVarInit(const clang::VarDecl &d) {
 
 void CIRGenFunction::emitAutoVarCleanups(const clang::VarDecl &d) {
   // Check the type for a cleanup.
-  if (QualType::DestructionKind dtorKind = d.needsDestruction(getContext()))
+  if (d.needsDestruction(getContext()))
     cgm.errorNYI(d.getSourceRange(), "emitAutoVarCleanups: type cleanup");
 
   assert(!cir::MissingFeatures::opAllocaPreciseLifetime());
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 90a2fd2a5d806..96ac292f49ef5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -98,6 +98,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
 
     cgf.getCIRGenModule().errorNYI(loc,
                                    "emitScalarConversion for unequal types");
+    return {};
   }
 };
 
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
index 7861a48c93244..ad7560d83fb68 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp
@@ -13,6 +13,7 @@
 #include "CIRGenFunction.h"
 
 #include "CIRGenCall.h"
+#include "CIRGenValue.h"
 #include "mlir/IR/Location.h"
 #include "clang/AST/GlobalDecl.h"
 #include "clang/CIR/MissingFeatures.h"
@@ -134,10 +135,9 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, mlir::Location rhs) {
   return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
 }
 
-mlir::LogicalResult CIRGenFunction::declare(mlir::Value addrVal,
-                                            const Decl *var, QualType ty,
-                                            mlir::Location loc,
-                                            CharUnits alignment, bool isParam) {
+void CIRGenFunction::declare(mlir::Value addrVal, const Decl *var, QualType ty,
+                             mlir::Location loc, CharUnits alignment,
+                             bool isParam) {
   const auto *namedVar = dyn_cast_or_null<NamedDecl>(var);
   assert(namedVar && "Needs a named decl");
   assert(!cir::MissingFeatures::cgfSymbolTable());
@@ -147,8 +147,6 @@ mlir::LogicalResult CIRGenFunction::declare(mlir::Value addrVal,
     allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext()));
   if (ty->isReferenceType() || ty.isConstQualified())
     allocaOp.setConstantAttr(mlir::UnitAttr::get(&getMLIRContext()));
-
-  return mlir::success();
 }
 
 void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType,
@@ -306,6 +304,7 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
     getCIRGenModule().errorNYI(e->getSourceRange(),
                                std::string("l-value not implemented for '") +
                                    e->getStmtClassName() + "'");
+    return LValue();
     break;
   case Expr::DeclRefExprClass:
     return emitDeclRefLValue(cast<DeclRefExpr>(e));
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index 6b383378ae764..cf896d3c0a946 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -97,9 +97,9 @@ class CIRGenFunction : public CIRGenTypeCache {
 private:
   /// Declare a variable in the current scope, return success if the variable
   /// wasn't declared yet.
-  mlir::LogicalResult declare(mlir::Value addrVal, const clang::Decl *var,
-                              clang::QualType ty, mlir::Location loc,
-                              clang::CharUnits alignment, bool isParam = false);
+  void declare(mlir::Value addrVal, const clang::Decl *var, clang::QualType ty,
+               mlir::Location loc, clang::CharUnits alignment,
+               bool isParam = false);
 
 public:
   mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty,

std::string("l-value not implemented for '") +
e->getStmtClassName() + "'");
return LValue();
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you added the return, I think you should get rid of the break;, which is now dead code.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@andykaylor andykaylor merged commit 6f25614 into llvm:main Mar 4, 2025
11 checks passed
@andykaylor andykaylor deleted the cir-fix-warnings branch March 4, 2025 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants