Fix: <rdar://problem/7242006> [RegionStore] compound literal assignment with floats not honored


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82575 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 3e9ed5b..a6c3c66 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -2263,6 +2263,7 @@
     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()) {
diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp
index 8b5848f..b54fa27 100644
--- a/lib/Analysis/RegionStore.cpp
+++ b/lib/Analysis/RegionStore.cpp
@@ -1397,6 +1397,7 @@
     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 @@
       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.
diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m
index c5bc0a6..4c75348 100644
--- a/test/Analysis/misc-ps-region-store.m
+++ b/test/Analysis/misc-ps-region-store.m
@@ -181,4 +181,17 @@
   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}}
+}
 
diff --git a/test/Analysis/misc-ps.m b/test/Analysis/misc-ps.m
index c7074d1..f877d44 100644
--- a/test/Analysis/misc-ps.m
+++ b/test/Analysis/misc-ps.m
@@ -643,3 +643,10 @@
             // 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
+}
+