From 1c61b472b24e7a61b91d535c030c92cd1fd8c7ee Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 23 Jul 2008 22:19:56 +0000 Subject: [PATCH] Don't flag dead stores when the result of a preincrement/predecrement is used in an enclosing expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53964 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CheckDeadStores.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index 005c71a580..433e61154f 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/lib/Analysis/CheckDeadStores.cpp @@ -153,6 +153,11 @@ public: if (!U->isIncrementOp()) return; + // Don't flag dead stores when the result of a preincrement/predecrement + // is used in an enclosing expression. + if (U->isPrefix() && Parents.isSubExpr(U)) + return; + Expr *Ex = U->getSubExpr()->IgnoreParenCasts(); if (DeclRefExpr* DR = dyn_cast(Ex)) @@ -161,7 +166,7 @@ public: else if (DeclStmt* DS = dyn_cast(S)) // Iterate through the decls. Warn if any initializers are complex // expressions that are not live (never used). - for (ScopedDecl* SD = DS->getDecl(); SD; SD = SD->getNextDeclarator()) { + for (ScopedDecl* SD = DS->getDecl(); SD; SD = SD->getNextDeclarator()) { VarDecl* V = dyn_cast(SD); if (!V) continue; -- 2.50.1