Rework codegen of case ranges
 - Fix multiple issues with the way case ranges were emitted, see test
   cases details about the specific issues.

 - The root issue was not being careful about how basic blocks were
   emitted which led to them being chained together incorrectly,
   resulting in improper control flow.

 - Fixes <rdar://problem/6098585>


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54006 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/rdr-6098585-empty-case-range.c b/test/CodeGen/rdr-6098585-empty-case-range.c
new file mode 100644
index 0000000..2dc3cf3
--- /dev/null
+++ b/test/CodeGen/rdr-6098585-empty-case-range.c
@@ -0,0 +1,23 @@
+// RUN: clang --emit-llvm-bc -o - %s | opt -std-compile-opts | llvm-dis > %t &&
+// RUN: grep "ret i32" %t | count 2 &&
+// RUN: grep "ret i32 3" %t | count 2
+
+// This generated incorrect code because of poor switch chaining.
+int f1(int x) {
+  switch(x) {
+  default:
+    return 3;
+  case 10 ... 0xFFFFFFFF:
+    return 0;
+  }
+}
+
+// This just asserted because of the way case ranges were calculated.
+int f2(int x) {
+  switch (x) {
+  default:
+    return 3;
+  case 10 ... -1: 
+    return 0;
+  }
+}