]> granicus.if.org Git - clang/commitdiff
Minor bug fixes to corner cases where LiveVariables would crash on some CFGs
authorTed Kremenek <kremenek@apple.com>
Thu, 6 Sep 2007 23:25:10 +0000 (23:25 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 6 Sep 2007 23:25:10 +0000 (23:25 +0000)
that contained no declarations, or when a variable is declared but never used.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41756 91177308-0d34-0410-b5e6-96231b3b80d8

Analysis/LiveVariables.cpp

index b5248fe99e34940a83604100b4cc895753198522..6b25f9eee60f9d6e4f3183d006f4bccd0eabdd70 100644 (file)
@@ -40,7 +40,9 @@ public:
     
   void VisitStmt(Stmt* S);
   void VisitDeclRefExpr(DeclRefExpr* DR);
+  void VisitDeclStmt(DeclStmt* DS);
   void Register(Decl* D);
+  void RegisterDeclChain(Decl* D);
   void RegisterUsedDecls();
 };
 
@@ -50,7 +52,15 @@ void RegisterDecls::VisitStmt(Stmt* S) {
 }
 
 void RegisterDecls::VisitDeclRefExpr(DeclRefExpr* DR) {
-  for (Decl* D = DR->getDecl() ; D != NULL ; D = D->getNextDeclarator())
+  RegisterDeclChain(DR->getDecl());
+}
+
+void RegisterDecls::VisitDeclStmt(DeclStmt* DS) {
+  RegisterDeclChain(DS->getDecl());
+}
+
+void RegisterDecls::RegisterDeclChain(Decl* D) {
+  for (; D != NULL ; D = D->getNextDeclarator())
     Register(D);
 }
 
@@ -363,7 +373,6 @@ void LiveVariables::runOnCFG(const CFG& cfg, LiveVariablesAuditor* Auditor) {
 
 void LiveVariables::runOnBlock(const CFGBlock* B, LiveVariablesAuditor* Auditor)
 {
-  assert (NumDecls && "You must use runOnCFG before using runOnBlock.");
   LivenessTFuncs TF(*this,Auditor);
   TF.ProcessBlock(B);
 }