forked from OSchip/llvm-project
Enhance dead store checker to not flag preincrements to dead variables where the preincrement is a subexpression, e.g. foo(++x); This can cause false negatives, but will remove a whole class of false positives.
llvm-svn: 57554
This commit is contained in:
parent
e388725aef
commit
bb7818b666
|
@ -149,6 +149,13 @@ public:
|
|||
else if (UnaryOperator* U = dyn_cast<UnaryOperator>(S)) {
|
||||
if (!U->isIncrementOp())
|
||||
return;
|
||||
|
||||
// Handle: ++x within a subexpression. The solution is not warn
|
||||
// about preincrements to dead variables when the preincrement occurs
|
||||
// as a subexpression. This can lead to false negatives, e.g. "(++x);"
|
||||
// A generalized dead code checker should find such issues.
|
||||
if (U->isPrefix() && Parents.isSubExpr(U))
|
||||
return;
|
||||
|
||||
Expr *Ex = U->getSubExpr()->IgnoreParenCasts();
|
||||
|
||||
|
|
|
@ -74,9 +74,15 @@ int f10() {
|
|||
|
||||
int f11() {
|
||||
int x = 4;
|
||||
return ++x; // expected-warning{{never read}}
|
||||
return x++; // expected-warning{{never read}}
|
||||
}
|
||||
|
||||
int f11b() {
|
||||
int x = 4;
|
||||
return ++x; // no-warning
|
||||
}
|
||||
|
||||
|
||||
int f12a(int y) {
|
||||
int x = y; // expected-warning{{never read}}
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue