[clang] [CIR][NFC] Fix a build warning in CIRGenCall.cpp (PR #137366)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 25 10:16:17 PDT 2025


https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/137366

We have been getting a warning about a default statement in a fully covered switch statement. This change fixes that by removing the default, updating all paths to return a value rather than depending on a local variable which is returned immediately after the switch, and adding an llvm_unreachable for non-enum values.

>From 4871b6ad138e6f93d9f27798427d2ba95f65a399 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Fri, 25 Apr 2025 10:03:46 -0700
Subject: [PATCH] [CIR][NFC] Fix a build warning in CIRGenCall.cpp

We have been getting a warning about a default statement in a fully
covered switch statement. This change fixes that by removing the
default, updating all paths to return a value rather than depending
on a local variable which is returned immediately after the switch,
and adding an llvm_unreachable for non-enum values.
---
 clang/lib/CIR/CodeGen/CIRGenCall.cpp | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp
index 69266f79a88a5..fe8d502e504bd 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp
@@ -110,7 +110,6 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
   assert(!cir::MissingFeatures::opCallMustTail());
   assert(!cir::MissingFeatures::opCallReturn());
 
-  RValue ret;
   switch (retInfo.getKind()) {
   case cir::ABIArgInfo::Direct: {
     mlir::Type retCIRTy = convertType(retTy);
@@ -132,23 +131,22 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
 
         return RValue::get(results[0]);
       }
-      default:
+      case cir::TEK_Complex:
+      case cir::TEK_Aggregate:
         cgm.errorNYI(loc,
                      "unsupported evaluation kind of function call result");
+        return getUndefRValue(retTy);
       }
-    } else
-      cgm.errorNYI(loc, "unsupported function call form");
-
-    break;
+      llvm_unreachable("Invalid evaluation kind");
+    }
+    cgm.errorNYI(loc, "unsupported function call form");
+    return getUndefRValue(retTy);
   }
   case cir::ABIArgInfo::Ignore:
     // If we are ignoring an argument that had a result, make sure to construct
     // the appropriate return value for our caller.
-    ret = getUndefRValue(retTy);
-    break;
-  default:
-    cgm.errorNYI(loc, "unsupported return value information");
+    return getUndefRValue(retTy);
   }
 
-  return ret;
+  llvm_unreachable("Invalid return info kind");
 }



More information about the cfe-commits mailing list