re PR c++/70285 (ICE on valid code on x86_64-linux-gnu: verify_gimple failed)
authorJason Merrill <jason@redhat.com>
Mon, 21 Mar 2016 21:13:06 +0000 (17:13 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 21 Mar 2016 21:13:06 +0000 (17:13 -0400)
PR c++/70285
* cp-gimplify.c (cp_fold) [COND_EXPR]: Handle bit-fields.

From-SVN: r234384

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/g++.dg/other/bitfield5.C [new file with mode: 0644]

index cd98a53b0ac43ecc38a18f310fd134147c37a869..3912395c896340f5017d3014f6aac99d2279fe51 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-21  Jason Merrill  <jason@redhat.com>
+
+       PR c++/70285
+       * cp-gimplify.c (cp_fold) [COND_EXPR]: Handle bit-fields.
+
 2016-03-18  Jason Merrill  <jason@redhat.com>
 
        PR c++/70139
index 6a767fa13a4e0828092ce72e1886c26ab0842e61..9bf248216b8d7beb7b1da320ee862a47411433c1 100644 (file)
@@ -2130,6 +2130,12 @@ cp_fold (tree x)
       else
        x = fold (x);
 
+      /* A COND_EXPR might have incompatible types in branches if one or both
+        arms are bitfields.  If folding exposed such a branch, fix it up.  */
+      if (TREE_CODE (x) != code)
+       if (tree type = is_bitfield_expr_with_lowered_type (x))
+         x = fold_convert (type, x);
+
       break;
 
     case CALL_EXPR:
diff --git a/gcc/testsuite/g++.dg/other/bitfield5.C b/gcc/testsuite/g++.dg/other/bitfield5.C
new file mode 100644 (file)
index 0000000..b8cd4dd
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/70285
+
+int a;
+
+struct S
+{
+  int i:8;
+} b;
+
+int
+fn1 (bool x)
+{
+  (&fn1 ? b.i : a) = 42;
+  return (&fn1 ? b.i : a);
+}