[PATCH] Sema: Fix CheckReturnStackAddr when RetValExp is an explicit cast
Chongyu Zhu
lembacon at gmail.com
Fri Nov 8 20:32:58 PST 2013
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2132.1.patch
Type: text/x-patch
Size: 879 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131108/0e9052b9/attachment.bin>
More information about the cfe-commits
mailing list