forked from OSchip/llvm-project
Sema: Don't leave switch stack inconsistent when recovering
We would exit Sema::ActOnFinishSwitchStmt early if we didn't have a body. This would leave an extra SwitchStmt on the SwitchStack. This fixes PR21841. llvm-svn: 224237
This commit is contained in:
parent
c1eeb310d4
commit
418ad3ff10
|
@ -1015,7 +1015,7 @@ public:
|
|||
|
||||
SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
|
||||
SourceLocation getLocEnd() const LLVM_READONLY {
|
||||
return SubExprs[BODY]->getLocEnd();
|
||||
return SubExprs[BODY] ? SubExprs[BODY]->getLocEnd() : SubExprs[COND]->getLocEnd();
|
||||
}
|
||||
|
||||
// Iterators
|
||||
|
|
|
@ -730,9 +730,10 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
|
|||
assert(SS == getCurFunction()->SwitchStack.back() &&
|
||||
"switch stack missing push/pop!");
|
||||
|
||||
getCurFunction()->SwitchStack.pop_back();
|
||||
|
||||
if (!BodyStmt) return StmtError();
|
||||
SS->setBody(BodyStmt, SwitchLoc);
|
||||
getCurFunction()->SwitchStack.pop_back();
|
||||
|
||||
Expr *CondExpr = SS->getCond();
|
||||
if (!CondExpr) return StmtError();
|
||||
|
|
|
@ -220,3 +220,12 @@ bool bar0() {
|
|||
case bar5: ; // expected-error{{use of undeclared identifier 'bar5'}}
|
||||
}
|
||||
}
|
||||
|
||||
namespace pr21841 {
|
||||
void fn1() {
|
||||
switch (0)
|
||||
switch (0 // expected-note{{to match this '('}}
|
||||
{ // expected-error{{expected ')'}}
|
||||
}
|
||||
} // expected-error{{expected statement}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue