]> granicus.if.org Git - clang/commitdiff
Fix: <rdar://problem/7242006> [RegionStore] compound literal assignment with floats...
authorTed Kremenek <kremenek@apple.com>
Tue, 22 Sep 2009 21:19:14 +0000 (21:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 22 Sep 2009 21:19:14 +0000 (21:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82575 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/GRExprEngine.cpp
lib/Analysis/RegionStore.cpp
test/Analysis/misc-ps-region-store.m
test/Analysis/misc-ps.m

index 3e9ed5b7f33b9b87ec3fcb8c436e004a6ab734dd..a6c3c66a0a3d00414eec3d8b00a0b6a66926dbd5 100644 (file)
@@ -2263,6 +2263,7 @@ void GRExprEngine::VisitInitListExpr(InitListExpr* E, ExplodedNode* Pred,
     WorkList.reserve(NumInitElements);
     WorkList.push_back(InitListWLItem(Pred, StartVals, E->rbegin()));
     InitListExpr::reverse_iterator ItrEnd = E->rend();
+    assert(!(E->rbegin() == E->rend()));
 
     // Process the worklist until it is empty.
     while (!WorkList.empty()) {
index 8b5848f5236a7338186081c8a83ac6ef316d62a6..b54fa272a00cab1e4b27db81306d5332afffb8a0 100644 (file)
@@ -1397,6 +1397,7 @@ const GRState *RegionStoreManager::BindArray(const GRState *state,
     if (CAT->getElementType()->isStructureType())
       state = BindStruct(state, ER, *VI);
     else
+      // FIXME: Do we need special handling of nested arrays?
       state = Bind(state, ValMgr.makeLoc(ER), *VI);
   }
 
@@ -1448,14 +1449,14 @@ RegionStoreManager::BindStruct(const GRState *state, const TypedRegion* R,
       break;
 
     QualType FTy = (*FI)->getType();
-    FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
+    const FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
 
-    if (Loc::IsLocType(FTy) || FTy->isIntegerType())
-      state = Bind(state, ValMgr.makeLoc(FR), *VI);
-    else if (FTy->isArrayType())
+    if (FTy->isArrayType())
       state = BindArray(state, FR, *VI);
     else if (FTy->isStructureType())
       state = BindStruct(state, FR, *VI);
+    else
+      state = Bind(state, ValMgr.makeLoc(FR), *VI);
   }
 
   // There may be fewer values in the initialize list than the fields of struct.
index c5bc0a68ffc1fc25b2c87a3c3d82cfa41e7b4dbe..4c753484bc983c11c5973c205fb63d31f69770e2 100644 (file)
@@ -181,4 +181,17 @@ int rdar_test_7185607() {
   return s.x; // no-warning
 }
 
+// <rdar://problem/7242006> [RegionStore] compound literal assignment with
+//  floats not honored
+// This test case is mirrored in misc-ps.m, but this case is a negative.
+typedef float CGFloat;
+typedef struct _NSSize {
+    CGFloat width;
+    CGFloat height;
+} NSSize;
+
+CGFloat rdar7242006_negative(CGFloat x) {
+  NSSize y;
+  return y.width; // expected-warning{{garbage}}
+}
 
index c7074d153c122812dc16cf2e541e8af51d257567..f877d4449c6ab7443eb46a17e0ff2bb40db18836 100644 (file)
@@ -643,3 +643,10 @@ int rdar_7242015() {
             // using RegionStore.
 }
 
+// <rdar://problem/7242006> [RegionStore] compound literal assignment with
+//  floats not honored
+CGFloat rdar7242006(CGFloat x) {
+  NSSize y = (NSSize){x, 10};
+  return y.width; // no-warning
+}
+