diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-08-04 20:01:07 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-08-04 20:01:07 +0000 |
commit | 68957a919084ab8bbd1f01d534db1d6f31d0f459 (patch) | |
tree | d462c36a2c98525cf56f2bf33443c2bf2ba06f62 /lib/Sema/SemaChecking.cpp | |
parent | 44034db24bf59a53aa7699f4bbf59b939710bb3c (diff) |
Teach SemaChecking::CheckReturnStackAddr about ImplicitCastExprs that convert values to an lvalue. This allows us to warn (again) about returning references to stack variables. (fixes PR 7812).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110242 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index d17ea43984..0fcc0a7559 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -1952,7 +1952,7 @@ static DeclRefExpr* EvalAddr(Expr *E) { /// EvalVal - This function is complements EvalAddr in the mutual recursion. /// See the comments for EvalAddr for more details. static DeclRefExpr* EvalVal(Expr *E) { - +do { // We should only be called for evaluating non-pointer expressions, or // expressions with a pointer type that are not used as references but instead // are l-values (e.g., DeclRefExpr with a pointer type). @@ -1961,6 +1961,15 @@ static DeclRefExpr* EvalVal(Expr *E) { // viewed AST node. We then recursively traverse the AST by calling // EvalAddr and EvalVal appropriately. switch (E->getStmtClass()) { + case Stmt::ImplicitCastExprClass: { + ImplicitCastExpr *IE = cast<ImplicitCastExpr>(E); + if (IE->getCategory() == ImplicitCastExpr::LValue) { + E = IE->getSubExpr(); + continue; + } + return NULL; + } + case Stmt::DeclRefExprClass: { // DeclRefExpr: the base case. When we hit a DeclRefExpr we are looking // at code that refers to a variable's name. We check if it has local @@ -1973,9 +1982,11 @@ static DeclRefExpr* EvalVal(Expr *E) { return NULL; } - case Stmt::ParenExprClass: + case Stmt::ParenExprClass: { // Ignore parentheses. - return EvalVal(cast<ParenExpr>(E)->getSubExpr()); + E = cast<ParenExpr>(E)->getSubExpr(); + continue; + } case Stmt::UnaryOperatorClass: { // The only unary operator that make sense to handle here @@ -2024,6 +2035,7 @@ static DeclRefExpr* EvalVal(Expr *E) { default: return NULL; } +} while (true); } //===--- CHECK: Floating-Point comparisons (-Wfloat-equal) ---------------===// |