diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-23 23:44:04 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-23 23:44:04 +0000 |
commit | 8cfe5a784133d90bf329fd20801824a6f71bb8ca (patch) | |
tree | 074054ca6c3e71e178729248da6006d569804241 /lib/Sema/SemaStmt.cpp | |
parent | 21affc089773edc30be43ecb0022a48acdac7093 (diff) |
Explicitly track the condition variable within an "if" statement,
rather than burying it in a CXXConditionDeclExpr (that occassionally
hides behind implicit conversions). Similar changes for
switch, while, and do-while will follow, then the removal of
CXXConditionDeclExpr. This commit is the canary.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89717 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index ad3376b9c8..cecc9b32c1 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -242,8 +242,17 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, OwningExprResult CondResult(CondVal.release()); Expr *condExpr = CondResult.takeAs<Expr>(); - assert(condExpr && "ActOnIfStmt(): missing expression"); + + 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 + } + if (CheckBooleanCondition(condExpr, IfLoc)) { CondResult = condExpr; return StmtError(); @@ -265,7 +274,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, DiagnoseUnusedExprResult(elseStmt); CondResult.release(); - return Owned(new (Context) IfStmt(IfLoc, condExpr, thenStmt, + return Owned(new (Context) IfStmt(IfLoc, ConditionVar, condExpr, thenStmt, ElseLoc, elseStmt)); } |