]> granicus.if.org Git - clang/commitdiff
Distinguish between dead stores and dead initializations.
authorTed Kremenek <kremenek@apple.com>
Tue, 15 Jul 2008 18:06:32 +0000 (18:06 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 15 Jul 2008 18:06:32 +0000 (18:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53628 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/DeadStores.cpp
test/Analysis/conditional-op-missing-lhs.c

index 0bbd8786098175137fb9959a02fa5c5c21aefa46..b9d9382f6ce757abe84019b710add88041309b28 100644 (file)
@@ -37,16 +37,26 @@ public:
   
   virtual ~DeadStoreObs() {}
   
-  void Report(VarDecl* V, bool inEnclosing, SourceLocation L, SourceRange R) {
+  void Report(VarDecl* V, bool inEnclosing, SourceLocation L, SourceRange R,
+              bool isInitialization = false) {
 
-    std::string name(V->getName());    
-    std::string msg = inEnclosing
-      ? "Although the value stored to '" + name +
-        "' is used in the enclosing expression, the value is never actually"
-        " read from '" + name + "'"
-      : "Value stored to '" + name + "' is never read";
+    std::string name(V->getName());
     
-    BR.EmitBasicReport("dead store", msg.c_str(), L, R);    
+    if (isInitialization) {
+      std::string msg = "Value stored to '" + name +
+        "' during its initialization is never read";
+      
+      BR.EmitBasicReport("dead initialization", msg.c_str(), L, R);      
+    }
+    else {
+      std::string msg = inEnclosing
+        ? "Although the value stored to '" + name +
+          "' is used in the enclosing expression, the value is never actually"
+          " read from '" + name + "'"
+        : "Value stored to '" + name + "' is never read";
+    
+      BR.EmitBasicReport("dead store", msg.c_str(), L, R);
+    }
   }
   
   void CheckVarDecl(VarDecl* VD, Expr* Ex, Expr* Val,
@@ -124,7 +134,7 @@ public:
               // a warning.  This is because such initialization can be
               // due to defensive programming.
               if (!E->isConstantExpr(Ctx,NULL))
-                Report(V, false, V->getLocation(), E->getSourceRange());
+                Report(V, false, V->getLocation(), E->getSourceRange(), true);
             }
       }
   }
index 6296291cdfb4ed28e326effdfd389e0d09232ce1..9fbb9f198755a5704dc60c94bf7ea972bf60be81 100644 (file)
@@ -4,7 +4,7 @@ void f1()
 {
        int i;
        
-       int j = i ? : 1; // expected-warning{{use of uninitialized variable}} //expected-warning{{Value stored to 'j' is never read}}
+       int j = i ? : 1; // expected-warning{{use of uninitialized variable}} //expected-warning{{Value stored to 'j' during its initialization is never read}}
 }
 
 void *f2(int *i)