[clang] [clang] Add unreachable after fully covered switches, avoid GCC warnings. NFC. (PR #159330)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 17 04:46:18 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)

<details>
<summary>Changes</summary>

This avoids the following warnings:

    ../../clang/lib/AST/ExprConstant.cpp: In member function ‘bool {anonymous}::IntExprEvaluator::VisitBuiltinCallExpr(const clang::CallExpr*, unsigned int)’:
    ../../clang/lib/AST/ExprConstant.cpp:14104:3: warning: this statement may fall through [-Wimplicit-fallthrough=]
    14104 |   }
          |   ^
    ../../clang/lib/AST/ExprConstant.cpp:14105:3: note: here
    14105 |   case Builtin::BIstrlen:
          |   ^~~~
    ../../clang/lib/Driver/ToolChains/CommonArgs.cpp: In function ‘std::string clang::driver::tools::complexRangeKindToStr(clang::LangOptionsBase::ComplexRangeKind ’:
    ../../clang/lib/Driver/ToolChains/CommonArgs.cpp:3523:1: warning: control reaches end of non-void function [-Wreturn-type]
     3523 | }
          | ^

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


2 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+1) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+1) 


``````````diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 12e4e25bd29c4..15c4a323b7d6a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -14101,6 +14101,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
       return Success(Result, E);
     }
     }
+    llvm_unreachable("Fully covered switch above");
   }
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b50549219e4e8..08cd98fd04df0 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -3520,6 +3520,7 @@ std::string tools::complexRangeKindToStr(LangOptions::ComplexRangeKind Range) {
     return "none";
     break;
   }
+  llvm_unreachable("Fully covered switch above");
 }
 
 std::string

``````````

</details>


https://github.com/llvm/llvm-project/pull/159330


More information about the cfe-commits mailing list