<rdar://problem/12426557> Fixing the NSIndexSet data formatter

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@165341 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/examples/summaries/cocoa/NSIndexSet.py b/examples/summaries/cocoa/NSIndexSet.py
index a112901..a1656fe 100644
--- a/examples/summaries/cocoa/NSIndexSet.py
+++ b/examples/summaries/cocoa/NSIndexSet.py
@@ -32,8 +32,12 @@
 		if not(self.sys_params.types_cache.NSUInteger):
 			if self.sys_params.is_64_bit:
 				self.sys_params.types_cache.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedLong)
+				self.sys_params.types_cache.uint32 = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
 			else:
 				self.sys_params.types_cache.NSUInteger = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
+				self.sys_params.types_cache.uint32 = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
+		if not(self.sys_params.types_cache.uint32):
+			self.sys_params.types_cache.uint32 = self.valobj.GetType().GetBasicType(lldb.eBasicTypeUnsignedInt)
 		self.update();
 
 	def update(self):
@@ -44,21 +48,22 @@
 	# the count is stored in the set itself, 3 pointers into it
 	# otherwise, it will store a pointer to an additional data structure (2 pointers into itself) and this
 	# additional structure will contain the count two pointers deep
-	# to distinguish the two modes, one reads two pointers deep into the object data: if only the MSB
-	# is set, then we are in mode 1, using that area to store flags, otherwise, the read pointer is the
-	# location to go look for count in mode 2
+	# a bunch of flags allow us to detect an empty set, vs. a one-range set, vs. a multi-range set
 	def count(self):
 		logger = lldb.formatters.Logger.Logger()
 		mode_chooser_vo = self.valobj.CreateChildAtOffset("mode_chooser",
-							2*self.sys_params.pointer_size,
-							self.sys_params.types_cache.NSUInteger)
+							self.sys_params.pointer_size,
+							self.sys_params.types_cache.uint32)
 		mode_chooser =  mode_chooser_vo.GetValueAsUnsigned(0)
 		if self.sys_params.is_64_bit:
-			mode_chooser = mode_chooser & 0xFFFFFFFFFFFFFF00
-		else:
-			mode_chooser = mode_chooser & 0xFFFFFF00
-		if mode_chooser == 0:
+			mode_chooser = mode_chooser & 0x00000000FFFFFFFF
+		# empty set
+		if mode_chooser & 0x01 == 1:
+			return 0
+		# single range
+		if mode_chooser & 0x02 == 2:
 			mode = 1
+		# multi range
 		else:
 			mode = 2
 		if mode == 1:
@@ -66,9 +71,11 @@
 								3*self.sys_params.pointer_size,
 								self.sys_params.types_cache.NSUInteger)
 		else:
-			count_ptr = mode_chooser_vo.GetValueAsUnsigned(0)
+			count_ptr = self.valobj.CreateChildAtOffset("count_ptr",
+								2*self.sys_params.pointer_size,
+								self.sys_params.types_cache.NSUInteger)
 			count_vo = self.valobj.CreateValueFromAddress("count",
-								count_ptr+2*self.sys_params.pointer_size,
+								count_ptr.GetValueAsUnsigned()+2*self.sys_params.pointer_size,
 								self.sys_params.types_cache.NSUInteger)
 		return count_vo.GetValueAsUnsigned(0)
 
diff --git a/test/functionalities/data-formatter/data-formatter-objc/main.m b/test/functionalities/data-formatter/data-formatter-objc/main.m
index eebe9f3..56087ae 100644
--- a/test/functionalities/data-formatter/data-formatter-objc/main.m
+++ b/test/functionalities/data-formatter/data-formatter-objc/main.m
@@ -556,7 +556,7 @@
 	    NSIndexSet *iset2 = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(1, 512)];
 
 	    NSMutableIndexSet *imset = [[NSMutableIndexSet alloc] init];
-	    [imset addIndex:4];
+	    [imset addIndex:1936];
 	    [imset addIndex:7];
 	    [imset addIndex:9];
 	    [imset addIndex:11];