]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/62103 (Incorrect folding of bitfield in a union on big...
authorThomas Preud'homme <thomas.preudhomme@arm.com>
Wed, 13 Aug 2014 09:37:41 +0000 (09:37 +0000)
committerThomas Preud'homme <thopre01@gcc.gnu.org>
Wed, 13 Aug 2014 09:37:41 +0000 (09:37 +0000)
2014-08-13  Thomas Preud'homme  <thomas.preudhomme@arm.com>

    Backport from mainline
    2014-08-12  Thomas Preud'homme  <thomas.preudhomme@arm.com>

    gcc/
    PR middle-end/62103
    * gimple-fold.c (fold_ctor_reference): Don't fold in presence of
    bitfields, that is when size doesn't match the size of type or the
    size of the constructor.

    gcc/testsuite/
    PR middle-end/62103
    * gcc.c-torture/execute/bitfld-6.c: New test.

From-SVN: r213899

gcc/ChangeLog
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/bitfld-6.c [new file with mode: 0644]

index 25ac61f9356a27df839cdac392495bb0e7c75fbf..e7771545c2084d11a3e1a732322ae0844a8268e3 100644 (file)
@@ -1,3 +1,13 @@
+2014-08-13  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       Backport from mainline
+       2014-08-12  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       PR middle-end/62103
+       * gimple-fold.c (fold_ctor_reference): Don't fold in presence of
+       bitfields, that is when size doesn't match the size of type or the
+       size of the constructor.
+
 2014-08-12  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        Backport patch from mainline
index 5d08169b8b598f726f2c750dd35a40d6b1319e36..80020a99e08aa45f39e17adcfaf134f9159e5abd 100644 (file)
@@ -2955,8 +2955,8 @@ fold_ctor_reference (tree type, tree ctor, unsigned HOST_WIDE_INT offset,
      result.  */
   if (!AGGREGATE_TYPE_P (TREE_TYPE (ctor)) && !offset
       /* VIEW_CONVERT_EXPR is defined only for matching sizes.  */
-      && operand_equal_p (TYPE_SIZE (type),
-                         TYPE_SIZE (TREE_TYPE (ctor)), 0))
+      && !compare_tree_int (TYPE_SIZE (type), size)
+      && !compare_tree_int (TYPE_SIZE (TREE_TYPE (ctor)), size))
     {
       ret = canonicalize_constructor_val (unshare_expr (ctor), from_decl);
       ret = fold_unary (VIEW_CONVERT_EXPR, type, ret);
index d55ac28b2dcaf7f7931e438911d7fb8182eac4ae..bcb2b66eff97e6756b860c6abfc719cc3d5caf58 100644 (file)
@@ -1,3 +1,11 @@
+2014-08-13  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       Backport from mainline
+       2014-08-12  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       PR middle-end/62103
+       * gcc.c-torture/execute/bitfld-6.c: New test.
+
 2014-08-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gcc.c-torture/execute/bitfld-6.c b/gcc/testsuite/gcc.c-torture/execute/bitfld-6.c
new file mode 100644 (file)
index 0000000..50927dc
--- /dev/null
@@ -0,0 +1,23 @@
+union U
+{
+  const int a;
+  unsigned b : 20;
+};
+
+static union U u = { 0x12345678 };
+
+/* Constant folding used to fail to account for endianness when folding a
+   union.  */
+
+int
+main (void)
+{
+#ifdef __BYTE_ORDER__
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+  return u.b - 0x45678;
+#else
+  return u.b - 0x12345;
+#endif
+#endif
+  return 0;
+}