[cfe-commits] r44984 - /cfe/trunk/Analysis/UninitializedValues.cpp

Ted Kremenek kremenek at apple.com
Wed Dec 12 21:14:22 PST 2007


Author: kremenek
Date: Wed Dec 12 23:14:22 2007
New Revision: 44984

URL: http://llvm.org/viewvc/llvm-project?rev=44984&view=rev
Log:
For uninitialized values analysis, added special treatment for declarations
of array types.  For things like:

  char x[10];
  
we should treat "x" as being initialized, because the variable "x" really
refers to the memory block of the array. Clearly x[1] is uninitialized, but
expressions like "(char*) x" really do refer to an initialized value. This
simple dataflow analysis does not reason about the contents of arrays.

This fixes: PR 1859 (http://llvm.org/bugs/show_bug.cgi?id=1859)

Modified:
    cfe/trunk/Analysis/UninitializedValues.cpp

Modified: cfe/trunk/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/UninitializedValues.cpp?rev=44984&r1=44983&r2=44984&view=diff

==============================================================================
--- cfe/trunk/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/Analysis/UninitializedValues.cpp Wed Dec 12 23:14:22 2007
@@ -124,7 +124,22 @@
     if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(D)) {
       if (Stmt* I = VD->getInit()) 
         V(VD,AD) = AD.FullUninitTaint ? V(cast<Expr>(I),AD) : Initialized;
-      else V(VD,AD) = Uninitialized;
+      else {
+        // Special case for declarations of array types.  For things like:
+        //
+        //  char x[10];
+        //
+        // we should treat "x" as being initialized, because the variable
+        // "x" really refers to the memory block.  Clearly x[1] is
+        // uninitialized, but expressions like "(char *) x" really do refer to 
+        // an initialized value.  This simple dataflow analysis does not reason 
+        // about the contents of arrays, although it could be potentially
+        // extended to do so if the array were of constant size.
+        if (VD->getType()->isArrayType())
+          V(VD,AD) = Initialized;
+        else        
+          V(VD,AD) = Uninitialized;
+      }
     }
       
   return Uninitialized; // Value is never consumed.





More information about the cfe-commits mailing list