Hi, This is actually the same as http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131104/092692.html before I realized that I should use http://llvm-reviews.chandlerc.com to send patch for review.
Anyway, thanks for review :-) Regards, Chongyu Zhu On Nov 9, 2013, at 12:32 PM, Chongyu Zhu <[email protected]> wrote: > I have found that `Sema::CheckReturnStackAddr` failed to generate warnings > for `diag::warn_ret_stack_ref` and `diag::warn_ret_local_temp_ref` when the > return value expression is an explicit cast. > > Provided the following code, > >> const int &test1() >> { >> return 0; >> } >> >> const int &test2() >> { >> int val = 0; >> return val; >> } >> >> const int &test3() >> { >> return static_cast<const int &>(0); >> } >> >> const int &test4() >> { >> int val = 0; >> return static_cast<const int &>(val); >> } > > Clang (as of r194251) generates warnings for `test1` and `test2`, however, > no warnings are given for `test3` and `test4`. > > GCC (4.8.1) is able to successfully generate warnings for all of the above. > > http://llvm-reviews.chandlerc.com/D2132 > > Files: > lib/Sema/SemaChecking.cpp > > Index: lib/Sema/SemaChecking.cpp > =================================================================== > --- lib/Sema/SemaChecking.cpp > +++ lib/Sema/SemaChecking.cpp > @@ -4192,10 +4192,17 @@ > > E = E->IgnoreParens(); > switch (E->getStmtClass()) { > - case Stmt::ImplicitCastExprClass: { > - ImplicitCastExpr *IE = cast<ImplicitCastExpr>(E); > - if (IE->getValueKind() == VK_LValue) { > - E = IE->getSubExpr(); > + case Stmt::ImplicitCastExprClass: > + case Stmt::CStyleCastExprClass: > + case Stmt::CXXStaticCastExprClass: > + case Stmt::CXXDynamicCastExprClass: > + case Stmt::CXXReinterpretCastExprClass: > + case Stmt::CXXConstCastExprClass: > + case Stmt::CXXFunctionalCastExprClass: > + case Stmt::ObjCBridgedCastExprClass: { > + CastExpr *CE = cast<CastExpr>(E); > + if (CE->getValueKind() == VK_LValue) { > + E = CE->getSubExpr(); > continue; > } > return NULL; > <D2132.1.patch> _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
