re PR middle-end/38422 (union/bitfield causes cc1/cc1plus to run out of memory.)
authorJakub Jelinek <jakub@redhat.com>
Sat, 6 Dec 2008 12:47:15 +0000 (13:47 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 6 Dec 2008 12:47:15 +0000 (13:47 +0100)
PR middle-end/38422
* fold-const.c (fold_unary) <CASE_CONVERT>: Don't convert MULT_EXPR
operands to mult_type if it isn't narrower than op0's type.

* gcc.c-torture/execute/pr38422.c: New test.

From-SVN: r142521

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr38422.c [new file with mode: 0644]

index 248ba67c660d9dcba3b38e2840d069ec43ac53d1..89d28bc1bbc924281d1663cfa88922a19080878d 100644 (file)
@@ -1,3 +1,9 @@
+2008-12-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/38422
+       * fold-const.c (fold_unary) <CASE_CONVERT>: Don't convert MULT_EXPR
+       operands to mult_type if it isn't narrower than op0's type.
+
 2008-12-06  Jan Hubicka  <jh@suse.cz>
            Jakub Jelinek <jakub@redhat.com>
 
index 719b7877bd65737e0f6ebf889b48cb24e2b5ec7e..8c0cb1d153f9696a1b018103014c49c4e6ba8bf4 100644 (file)
@@ -8351,11 +8351,16 @@ fold_unary (enum tree_code code, tree type, tree op0)
            mult_type = type;
          else
            mult_type = unsigned_type_for (type);
-         
-         tem = fold_build2 (MULT_EXPR, mult_type,
-                            fold_convert (mult_type, TREE_OPERAND (op0, 0)),
-                            fold_convert (mult_type, TREE_OPERAND (op0, 1)));
-         return fold_convert (type, tem);
+
+         if (TYPE_PRECISION (mult_type) < TYPE_PRECISION (TREE_TYPE (op0)))
+           {
+             tem = fold_build2 (MULT_EXPR, mult_type,
+                                fold_convert (mult_type,
+                                              TREE_OPERAND (op0, 0)),
+                                fold_convert (mult_type,
+                                              TREE_OPERAND (op0, 1)));
+             return fold_convert (type, tem);
+           }
        }
 
       tem = fold_convert_const (code, type, op0);
index 2c7ee3cba637e9f3ba6897470d27cbfa19769d73..bf19792649c04a987d636d3c7fe05b29d245c665 100644 (file)
@@ -1,3 +1,8 @@
+2008-12-06  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/38422
+       * gcc.c-torture/execute/pr38422.c: New test.
+
 2008-12-06  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/38415
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr38422.c b/gcc/testsuite/gcc.c-torture/execute/pr38422.c
new file mode 100644 (file)
index 0000000..e36879d
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR middle-end/38422 */
+
+extern void abort (void);
+
+struct S
+{
+  int s : (sizeof (int) * __CHAR_BIT__ - 2);
+} s;
+
+void
+foo (void)
+{
+  s.s *= 2;
+}
+
+int
+main ()
+{
+  s.s = 24;
+  foo ();
+  if (s.s != 48)
+    abort ();
+  return 0;
+}