[clang] [clang][CodeGen] Fix crash on if/switch init-statement ending in noreturn (PR #201047)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 2 13:50:54 PDT 2026
================
@@ -2374,9 +2379,14 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
RunCleanupsScope ConditionScope(*this);
- if (S.getInit())
+ if (S.getInit()) {
EmitStmt(S.getInit());
+ // The init statement may have cleared the insertion point (e.g. it ended in
+ // a 'noreturn' call); the condition emitted below needs a valid one.
+ EnsureInsertPoint();
----------------
efriedma-quic wrote:
If we wanted to be "optimal", instead of using EnsureInsertPoint to emit a bunch of dead code, we could skip emitting the "switch". But doing that correctly is probably too complicated to be worthwhile, given this situation shouldn't show up in real code, so this patch seems fine.
https://github.com/llvm/llvm-project/pull/201047
More information about the cfe-commits
mailing list