[cfe-commits] r51395 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Analysis/DeadStores.cpp test/Analysis/dead-stores.c

Ted Kremenek kremenek at apple.com
Wed May 21 15:59:16 PDT 2008


Author: kremenek
Date: Wed May 21 17:59:16 2008
New Revision: 51395

URL: http://llvm.org/viewvc/llvm-project?rev=51395&view=rev
Log:
Improve dead stores diagnostics to include the variable name.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Analysis/DeadStores.cpp
    cfe/trunk/test/Analysis/dead-stores.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=51395&r1=51394&r2=51395&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed May 21 17:59:16 2008
@@ -1007,9 +1007,6 @@
 DIAG(warn_selfcomparison,WARNING,
      "self-comparison always results in a constant value.")
 
-// CHECK: stores to variables that are no longer live (dead stores)
-DIAG(warn_dead_store, WARNING, "value stored to variable is never used")
-
 // CHECK: use of uninitialized values
 DIAG(warn_uninit_val, WARNING, "use of uninitialized variable")
 

Modified: cfe/trunk/lib/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DeadStores.cpp?rev=51395&r1=51394&r2=51395&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/DeadStores.cpp Wed May 21 17:59:16 2008
@@ -20,6 +20,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/AST/ASTContext.h"
 #include "llvm/Support/Compiler.h"
+#include <sstream>
 
 using namespace clang;
 
@@ -35,16 +36,22 @@
   
   virtual ~DeadStoreObs() {}
   
+  unsigned GetDiag(VarDecl* VD) {
+    std::ostringstream os;
+    os << "value stored to '" << VD->getName() << "' is never used";        
+    return Diags.getCustomDiagID(Diagnostic::Warning, os.str().c_str());     
+  }
+  
   void CheckDeclRef(DeclRefExpr* DR, Expr* Val,
                     const LiveVariables::AnalysisDataTy& AD,
                     const LiveVariables::ValTy& Live) {
     
     if (VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl()))
       if (VD->hasLocalStorage() && !Live(VD, AD)) {
-        SourceRange R = Val->getSourceRange();
+        SourceRange R = Val->getSourceRange();        
         Diags.Report(&Client,
                      Ctx.getFullLoc(DR->getSourceRange().getBegin()),
-                     diag::warn_dead_store, 0, 0, &R, 1);
+                     GetDiag(VD), 0, 0, &R, 1);
       }
   }
   
@@ -94,7 +101,7 @@
                 SourceRange R = E->getSourceRange();
                 Diags.Report(&Client,
                              Ctx.getFullLoc(V->getLocation()),
-                             diag::warn_dead_store, 0, 0, &R, 1);
+                             GetDiag(V), 0, 0, &R, 1);
               }
             }
           }

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=51395&r1=51394&r2=51395&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Wed May 21 17:59:16 2008
@@ -3,12 +3,12 @@
 void f1() {
   int k, y;
   int abc=1;
-  long idx=abc+3*5; // expected-warning {{value stored to variable is never used}}
+  long idx=abc+3*5; // expected-warning {{never used}}
 }
 
 void f2(void *b) {
  char *c = (char*)b; // no-warning
- char *d = b+1; // expected-warning {{value stored to variable is never used}}
+ char *d = b+1; // expected-warning {{never used}}
  printf("%s", c);
 }
 
@@ -27,19 +27,19 @@
   if (k)
     f1();
     
-  k = 2;  // expected-warning {{value stored to variable is never used}}
+  k = 2;  // expected-warning {{never used}}
 }
 
 void f5() {
 
   int x = 4; // no-warning
-  int *p = &x; // expected-warning{{value stored to variable is never used}}
+  int *p = &x; // expected-warning{{never used}}
 
 }
 
 int f6() {
   
   int x = 4;
-  ++x; // expected-warning{{value stored to variable is never used}}
+  ++x; // expected-warning{{never used}}
   return 1;
 }





More information about the cfe-commits mailing list