re PR c++/65556 (ICE: verify_gimple failed (type precision mismatch in switch statement))
authorMarek Polacek <polacek@redhat.com>
Fri, 27 Mar 2015 16:46:44 +0000 (16:46 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 27 Mar 2015 16:46:44 +0000 (16:46 +0000)
PR c++/65556
* semantics.c (finish_switch_cond): If the unlowered type is not an
enum, use the type of the condition.

* c-c++-common/pr65556.c: New test.

From-SVN: r221738

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr65556.c [new file with mode: 0644]

index baed6e14732f620b87f2e8b0c4cc819574e056ec..9a3324fe306a0c0e90877d874180b1fb8a7df328 100644 (file)
@@ -1,3 +1,9 @@
+2015-03-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/65556
+       * semantics.c (finish_switch_cond): If the unlowered type is not an
+       enum, use the type of the condition.
+
 2015-03-27  Jason Merrill  <jason@redhat.com>
 
        PR c++/65509
index f325e41f417fa65dbbf946a6701881cca828587f..74af7e842c731f3ab5ac23b5bc3bbef02515fd91 100644 (file)
@@ -1165,6 +1165,8 @@ finish_switch_cond (tree cond, tree switch_stmt)
        }
       /* We want unlowered type here to handle enum bit-fields.  */
       orig_type = unlowered_expr_type (cond);
+      if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
+       orig_type = TREE_TYPE (cond);
       if (cond != error_mark_node)
        {
          /* Warn if the condition has boolean value.  */
index c1adea5ff192cce0fc8c34fac86ff9ba826e5ff0..a5863094050ba556632154fdc1cce66af61648c6 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-27  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/65556
+       * c-c++-common/pr65556.c: New test.
+
 2015-03-27  Jan Hubicka  <hubicka@ucw.cz>
 
        PR ipa/65600
diff --git a/gcc/testsuite/c-c++-common/pr65556.c b/gcc/testsuite/c-c++-common/pr65556.c
new file mode 100644 (file)
index 0000000..c6729a1
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR c++/65556 */
+/* { dg-do compile } */
+
+struct S
+{
+  long l: 1;
+  long l2: 41;
+  unsigned long ul: 1;
+  unsigned long ul2: 41;
+} s;
+
+void
+fn ()
+{
+  switch (s.l)
+    case 0:;
+  switch (s.ul)
+    case 0:;
+  switch (s.l2)
+    case 0:;
+  switch (s.ul2)
+    case 0:;
+}