diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-12 06:12:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-12 06:12:50 +0000 |
commit | 966c78b79004061c1f64feff96818b9f1d68ea58 (patch) | |
tree | 37a37c7048ddffa186ee50a7bde3e344afb078f0 /lib | |
parent | cf7cfe874c251b132401ccc46173ec20d5d84cf2 (diff) |
change Scope::WithinElse to be a normal scope flag, widen the
fields to two 16-bit values instead of using bitfields.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101020 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index b208c50c81..9b2227002f 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -643,6 +643,7 @@ Parser::OwningStmtResult Parser::ParseIfStatement(AttributeList *Attr) { if (Tok.is(tok::kw_else)) { ElseLoc = ConsumeToken(); + ElseStmtLoc = Tok.getLocation(); // C99 6.8.4p3 - In C99, the body of the if statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do @@ -656,12 +657,14 @@ Parser::OwningStmtResult Parser::ParseIfStatement(AttributeList *Attr) { ParseScope InnerScope(this, Scope::DeclScope, C99orCXX && Tok.isNot(tok::l_brace)); - bool WithinElse = CurScope->isWithinElse(); - CurScope->setWithinElse(true); - ElseStmtLoc = Tok.getLocation(); + // Regardless of whether or not InnerScope actually pushed a scope, set the + // ElseScope flag for the innermost scope so we can diagnose use of the if + // condition variable in C++. + unsigned OldFlags = CurScope->getFlags(); + CurScope->setFlags(OldFlags | Scope::ElseScope); ElseStmt = ParseStatement(); - CurScope->setWithinElse(WithinElse); - + CurScope->setFlags(OldFlags); + // Pop the 'else' scope if needed. InnerScope.Exit(); } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 263005908c..d6f135863d 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1105,16 +1105,15 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S, // Warn about constructs like: // if (void *X = foo()) { ... } else { X }. // In the else block, the pointer is always false. - if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) { Scope *CheckS = S; while (CheckS && CheckS->getControlParent()) { - if (CheckS->isWithinElse() && + if ((CheckS->getFlags() & Scope::ElseScope) && CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) { ExprError(Diag(NameLoc, diag::warn_value_always_zero) << Var->getDeclName() - << (Var->getType()->isPointerType()? 2 : - Var->getType()->isBooleanType()? 1 : 0)); + << (Var->getType()->isPointerType() ? 2 : + Var->getType()->isBooleanType() ? 1 : 0)); break; } |