diff options
| author | Ted Kremenek <kremenek@apple.com> | 2007-09-06 23:39:53 +0000 | 
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2007-09-06 23:39:53 +0000 | 
| commit | 3ce57c6baf0961108f76d3d377ff554b765b848e (patch) | |
| tree | b59fc47c10643b1dcb95b6125f43766ac26255fe /clang | |
| parent | 10e78707468ef371ab81cb55ac95be19ec87d6d0 (diff) | |
| download | bcm5719-llvm-3ce57c6baf0961108f76d3d377ff554b765b848e.tar.gz bcm5719-llvm-3ce57c6baf0961108f76d3d377ff554b765b848e.zip | |
Added more checking in "dead stores" for values that are initialized
but never used.
Fix a bug in LiveVariables where uses on the LHS of self-assign
operators (e.g +=, *=, etc) would not be properly recorded in the
liveness state of the variable.
llvm-svn: 41757
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Analysis/DeadStores.cpp | 13 | ||||
| -rw-r--r-- | clang/Analysis/LiveVariables.cpp | 5 | 
2 files changed, 17 insertions, 1 deletions
| diff --git a/clang/Analysis/DeadStores.cpp b/clang/Analysis/DeadStores.cpp index e7077ecae31..f79aa6ae047 100644 --- a/clang/Analysis/DeadStores.cpp +++ b/clang/Analysis/DeadStores.cpp @@ -47,6 +47,19 @@ public:          }        }      } +    else if(DeclStmt* DS = dyn_cast<DeclStmt>(S)) { +      // Iterate through the decls.  Warn if any of them (which have +      // initializers) are not live. +      for (Decl* D = DS->getDecl() ; D != NULL ; D = D->getNextDeclarator()) +        if (VarDecl* V = dyn_cast<VarDecl>(D)) +          if (Expr* E = V->getInit()) +            if (!L.isLive(Live,D)) { +              SourceRange R = E->getSourceRange(); +              PP.getDiagnostics().Report(D->getLocation(), +                                         diag::warn_dead_store, 0, 0, +                                         &R,1); +            } +    }    }  }; diff --git a/clang/Analysis/LiveVariables.cpp b/clang/Analysis/LiveVariables.cpp index 6b25f9eee60..bf4437470e3 100644 --- a/clang/Analysis/LiveVariables.cpp +++ b/clang/Analysis/LiveVariables.cpp @@ -252,7 +252,10 @@ void LivenessTFuncs::VisitAssign(BinaryOperator* B) {      // We only need to register kills once, so we check if this block      // has been previously processed.      if (!blockPreviouslyProcessed) -      V.AddKill(CurrentStmt,DR);     +      V.AddKill(CurrentStmt,DR); +       +    if (B->getOpcode() != BinaryOperator::Assign) +      Visit(LHS);    }    else      Visit(LHS); | 

