From: Ted Kremenek Date: Mon, 27 Aug 2007 16:39:17 +0000 (+0000) Subject: Updated checker for "return of address of stack variable" to look for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96eabe0838ccd1d5a5d24a648b932763cdf3fa31;p=clang Updated checker for "return of address of stack variable" to look for implicit casts from T to T& at the topmost part of the return-value expression. This checking may be needed within EvalAddr later on. We'll wait until test cases show this kind of logic is necessary (as more C++ features are implemented in clang). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41493 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaChecking.cpp b/Sema/SemaChecking.cpp index e03507b796..c027fa794c 100644 --- a/Sema/SemaChecking.cpp +++ b/Sema/SemaChecking.cpp @@ -410,10 +410,12 @@ Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType, } // Perform checking for stack values returned by reference. else if (lhsType->isReferenceType()) { - if (DeclRefExpr *DR = EvalVal(RetValExp)) - Diag(DR->getLocStart(), diag::warn_ret_stack_ref, - DR->getDecl()->getIdentifier()->getName(), - RetValExp->getSourceRange()); + // Check for an implicit cast to a reference. + if (ImplicitCastExpr *I = dyn_cast(RetValExp)) + if (DeclRefExpr *DR = EvalVal(I->getSubExpr())) + Diag(DR->getLocStart(), diag::warn_ret_stack_ref, + DR->getDecl()->getIdentifier()->getName(), + RetValExp->getSourceRange()); } }