]> granicus.if.org Git - clang/commitdiff
Teach static analyzer about the basics of handling new[]. We still don't simulate...
authorTed Kremenek <kremenek@apple.com>
Thu, 31 Mar 2011 04:04:48 +0000 (04:04 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 31 Mar 2011 04:04:48 +0000 (04:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128611 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CXXExprEngine.cpp
test/Analysis/misc-ps-region-store.cpp

index b015d4f264d786fad2e0d77ebf7973b0a799f8fe..b299fcc1c1d962dbcffa41279a90f73277787593 100644 (file)
@@ -199,20 +199,23 @@ void ExprEngine::VisitCXXDestructor(const CXXDestructorDecl *DD,
 
 void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
                                    ExplodedNodeSet &Dst) {
-  if (CNE->isArray()) {
-    // FIXME: allocating an array has not been handled.
-    return;
-  }
-
+  
   unsigned Count = Builder->getCurrentBlockCount();
   DefinedOrUnknownSVal symVal =
     svalBuilder.getConjuredSymbolVal(NULL, CNE, CNE->getType(), Count);
-  const MemRegion *NewReg = cast<loc::MemRegionVal>(symVal).getRegion();
-
+  const MemRegion *NewReg = cast<loc::MemRegionVal>(symVal).getRegion();  
   QualType ObjTy = CNE->getType()->getAs<PointerType>()->getPointeeType();
-
   const ElementRegion *EleReg = 
-                         getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
+    getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
+
+  if (CNE->isArray()) {
+    // FIXME: allocating an array requires simulating the constructors.
+    // For now, just return a symbolicated region.
+    const GRState *state = GetState(Pred);
+    state = state->BindExpr(CNE, loc::MemRegionVal(EleReg));
+    MakeNode(Dst, CNE, Pred, state);
+    return;
+  }
 
   // Evaluate constructor arguments.
   const FunctionProtoType *FnType = NULL;
index 3b8d4e378202e2ba26cab7eebf9efdf73214869e..26a31526b74ee6ed1a2dff833a829f0ff077bc95 100644 (file)
@@ -255,4 +255,12 @@ bool RDar9203355::foo(unsigned valA, int &result) const {
   return false;
 }
 
+// Test handling of new[].
+void rdar9212512() {
+  int *x = new int[10];
+  for (unsigned i = 0 ; i < 2 ; ++i) {
+    // This previously triggered an uninitialized values warning.
+    x[i] = 1;  // no-warning
+  }
+}