re PR c++/37819 (ice for bitfield code)
authorJakub Jelinek <jakub@redhat.com>
Tue, 14 Oct 2008 21:57:44 +0000 (23:57 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 14 Oct 2008 21:57:44 +0000 (23:57 +0200)
PR c++/37819
* cp-gimplify.c (cp_genericize_r): Only fold_convert COND_EXPR
arguments if they don't already have COND_EXPR's type.

* g++.dg/expr/bitfield11.C: New test.

From-SVN: r141118

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

index 73a1656..30110cc 100644 (file)
@@ -1,3 +1,9 @@
+2008-10-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/37819
+       * cp-gimplify.c (cp_genericize_r): Only fold_convert COND_EXPR
+       arguments if they don't already have COND_EXPR's type.
+
 2008-10-14  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/37650
index 1641be5..144de3f 100644 (file)
@@ -815,14 +815,18 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
        = (TREE_OPERAND (stmt, 2)
           ? is_bitfield_expr_with_lowered_type (TREE_OPERAND (stmt, 2))
           : NULL_TREE);
-      if (type_left)
+      if (type_left
+         && !useless_type_conversion_p (TREE_TYPE (stmt),
+                                        TREE_TYPE (TREE_OPERAND (stmt, 1))))
        {
          TREE_OPERAND (stmt, 1)
            = fold_convert (type_left, TREE_OPERAND (stmt, 1));
          gcc_assert (useless_type_conversion_p (TREE_TYPE (stmt),
                                                 type_left));
        }
-      if (type_right)
+      if (type_right
+         && !useless_type_conversion_p (TREE_TYPE (stmt),
+                                        TREE_TYPE (TREE_OPERAND (stmt, 2))))
        {
          TREE_OPERAND (stmt, 2)
            = fold_convert (type_right, TREE_OPERAND (stmt, 2));
index 8f3e7b4..12090cc 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-14  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/37819
+       * g++.dg/expr/bitfield11.C: New test.
+
 2008-10-14  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/37650
diff --git a/gcc/testsuite/g++.dg/expr/bitfield11.C b/gcc/testsuite/g++.dg/expr/bitfield11.C
new file mode 100644 (file)
index 0000000..bab303e
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/37819
+// { dg-do compile }
+
+struct A
+{
+  unsigned int a : 1;
+};
+
+bool
+foo (A *x, A *y)
+{
+  x->a = y ? y->a : true;
+}