]> granicus.if.org Git - clang/commitdiff
For uninitialized values analysis, added special treatment for declarations
authorTed Kremenek <kremenek@apple.com>
Thu, 13 Dec 2007 05:14:22 +0000 (05:14 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 13 Dec 2007 05:14:22 +0000 (05:14 +0000)
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)

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

Analysis/UninitializedValues.cpp

index 9651814b02d50be2a722ecd81d11091c583d63db..89ff1c20681bf8af920cf27754f7225d94fdb6ac 100644 (file)
@@ -124,7 +124,22 @@ bool TransferFuncs::VisitDeclStmt(DeclStmt* S) {
     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.