Skip to content

[CIR][NFS] Fix dead code return statement warning #142591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

AmrDeveloper
Copy link
Member

Fix the warning related to the missing return statement and multiple return statements

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Jun 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2025

@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)

Changes

Fix the warning related to the missing return statement and multiple return statements


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

1 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+3-5)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 77287ec45972d..9404d6d66cf20 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -102,8 +102,9 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
                                      mlir::Type dstTy) const {
     if (mlir::isa<cir::IntType>(dstTy))
       return builder.createBoolToInt(value, dstTy);
-    if (mlir::isa<cir::BoolType>(dstTy))
-      return value;
+
+    assert(mlir::isa<cir::BoolType>(dstTy) && "Expect bool type");
+    return value;
   }
 
   //===--------------------------------------------------------------------===//
@@ -1857,9 +1858,6 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) {
 
   // ZExt result to the expr type.
   return maybePromoteBoolResult(boolVal, cgf.convertType(e->getType()));
-
-  cgf.cgm.errorNYI("destination type for logical-not unary operator is NYI");
-  return {};
 }
 
 /// Return the size or alignment of the type of argument of the sizeof

@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2025

@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)

Changes

Fix the warning related to the missing return statement and multiple return statements


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

1 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+3-5)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 77287ec45972d..9404d6d66cf20 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -102,8 +102,9 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
                                      mlir::Type dstTy) const {
     if (mlir::isa<cir::IntType>(dstTy))
       return builder.createBoolToInt(value, dstTy);
-    if (mlir::isa<cir::BoolType>(dstTy))
-      return value;
+
+    assert(mlir::isa<cir::BoolType>(dstTy) && "Expect bool type");
+    return value;
   }
 
   //===--------------------------------------------------------------------===//
@@ -1857,9 +1858,6 @@ mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) {
 
   // ZExt result to the expr type.
   return maybePromoteBoolResult(boolVal, cgf.convertType(e->getType()));
-
-  cgf.cgm.errorNYI("destination type for logical-not unary operator is NYI");
-  return {};
 }
 
 /// Return the size or alignment of the type of argument of the sizeof

Copy link
Contributor

@xlauko xlauko left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

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

@mmha also posted a fix for the maybePromoteBoolResult here: #142673

The removal of the dead code below the return in VisitUnaryLNot should be done as it is here, but I have a slight preference for Morris' handling of the maybePromoteBoolResult return.

@AmrDeveloper AmrDeveloper force-pushed the cir_nfs_missing_ret_stmt branch from 5a47507 to 0c59770 Compare June 3, 2025 21:53
@AmrDeveloper AmrDeveloper changed the title [CIR][NFS] Fix missing return statement warning [CIR][NFS] Fix dead code return statement warning Jun 3, 2025
Copy link
Contributor

@mmha mmha left a comment

Choose a reason for hiding this comment

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

LGTM (and thanks!)

@AmrDeveloper AmrDeveloper merged commit d7c7c46 into llvm:main Jun 4, 2025
11 checks passed
rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
Fix the warning related to the missing return statement and multiple
return statements
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
Fix the warning related to the missing return statement and multiple
return statements
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