diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-24 17:07:59 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-24 17:07:59 +0000 |
commit | d3d5301c44138b92bf01286183f5bf310cdd37cf (patch) | |
tree | 5e426515a870ee432cb704304b79058d3b042a24 /lib/Sema/SemaStmt.cpp | |
parent | c102297fb2857ef1af191a8e85e842cc3ac3239e (diff) |
Explicitly store the condition variable within switch statements, and
make sure that this variable is destroyed when we exit the switch
statement.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89776 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index cecc9b32c1..6ff3d638fe 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -280,7 +280,17 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Action::OwningStmtResult Sema::ActOnStartOfSwitchStmt(ExprArg cond) { - SwitchStmt *SS = new (Context) SwitchStmt(cond.takeAs<Expr>()); + Expr *condExpr = cond.takeAs<Expr>(); + VarDecl *ConditionVar = 0; + if (CXXConditionDeclExpr *Cond = dyn_cast<CXXConditionDeclExpr>(condExpr)) { + ConditionVar = Cond->getVarDecl(); + condExpr = DeclRefExpr::Create(Context, 0, SourceRange(), ConditionVar, + ConditionVar->getLocation(), + ConditionVar->getType().getNonReferenceType()); + // FIXME: Leaks the old condExpr + } + + SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar, condExpr); getSwitchStack().push_back(SS); return Owned(SS); } |