[clang] [clang][bytecode] Don't crash on erroneous switch conditions (PR #147533)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 8 07:09:35 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Not attaching a test since I've only seen this when compiling a large c++26 test case as c++17.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 51c234d0d0471..ee9c3890794af 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5629,6 +5629,9 @@ bool Compiler<Emitter>::visitContinueStmt(const ContinueStmt *S) {
 template <class Emitter>
 bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
   const Expr *Cond = S->getCond();
+  if (Cond->containsErrors())
+    return false;
+
   PrimType CondT = this->classifyPrim(Cond->getType());
   LocalScope<Emitter> LS(this);
 

``````````

</details>


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


More information about the cfe-commits mailing list