[clang] [clang] Clean up switch stack when transforming an invalid body (PR #211162)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 22 09:00:30 PDT 2026
================
@@ -8461,8 +8461,10 @@ TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
// Transform the body of the switch statement.
StmtResult Body = getDerived().TransformStmt(S->getBody());
+ // Finish the switch even on error to pop it from Sema's switch stack.
if (Body.isInvalid())
- return StmtError();
+ return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
+ nullptr);
----------------
Sirraide wrote:
`ActOnStartOfSwitchStmt()` pushes an entry onto the stack iff it doesn’t return `StmtError()`, i.e. if it fails, we never pushed an entry to begin with; this is consistent w/ other places where we push similar state that needs to be popped separately, so relying on this here makes sense.
Calling RebuildSwitchStmtBody() irrespective of whether transforming the body succeeded is the right thing to do (we also do it like that in the parser).
https://github.com/llvm/llvm-project/pull/211162
More information about the cfe-commits
mailing list