summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-11-24 21:15:44 +0000
committerDouglas Gregor <dgregor@apple.com>2009-11-24 21:15:44 +0000
commit680f861d74f39bb29ad87346f764da7cc392c5aa (patch)
tree5b58f11c0249187ebfd9e8ea7081a5050f61015a /clang/lib/Sema
parent3c9beab48a6af525b851bfc44b55ddb2b35c5237 (diff)
downloadbcm5719-llvm-680f861d74f39bb29ad87346f764da7cc392c5aa.tar.gz
bcm5719-llvm-680f861d74f39bb29ad87346f764da7cc392c5aa.zip
Clean up the AST for while loops and fix several problems with
cleanups for while loops: 1) Make sure that we destroy the condition variable of a while statement each time through the loop for, e.g., while (shared_ptr<WorkInt> p = getWorkItem()) { // ... } 2) Make sure that we always enter a new cleanup scope for the body of the while loop, even when there is no compound expression, e.g., while (blah) RAIIObject raii(blah+1); llvm-svn: 89800
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp12
-rw-r--r--clang/lib/Sema/TreeTransform.h13
2 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 6ff3d638fe9..61d48cb63eb 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -720,6 +720,15 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, StmtArg Body) {
Expr *condExpr = CondArg.takeAs<Expr>();
assert(condExpr && "ActOnWhileStmt(): 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, WhileLoc)) {
CondArg = condExpr;
return StmtError();
@@ -729,7 +738,8 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, StmtArg Body) {
DiagnoseUnusedExprResult(bodyStmt);
CondArg.release();
- return Owned(new (Context) WhileStmt(condExpr, bodyStmt, WhileLoc));
+ return Owned(new (Context) WhileStmt(ConditionVar, condExpr, bodyStmt,
+ WhileLoc));
}
Action::OwningStmtResult
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index e1d0bba4a4e..202e16e31e3 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -3139,7 +3139,18 @@ template<typename Derived>
Sema::OwningStmtResult
TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
// Transform the condition
- OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
+ OwningExprResult Cond(SemaRef);
+ VarDecl *ConditionVar = 0;
+ if (S->getConditionVariable()) {
+ ConditionVar
+ = cast_or_null<VarDecl>(
+ getDerived().TransformDefinition(S->getConditionVariable()));
+ if (!ConditionVar)
+ return SemaRef.StmtError();
+
+ Cond = getSema().CheckConditionVariable(ConditionVar);
+ } else
+ Cond = getDerived().TransformExpr(S->getCond());
if (Cond.isInvalid())
return SemaRef.StmtError();
OpenPOWER on IntegriCloud