]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/51759 (miscompile writes past end of bitfield)
authorMartin Jambor <mjambor@suse.cz>
Mon, 9 Jan 2012 18:40:09 +0000 (19:40 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Mon, 9 Jan 2012 18:40:09 +0000 (19:40 +0100)
2012-01-09  Martin Jambor  <mjambor@suse.cz>

PR tree-optimization/51759

Backport from mainline
2010-09-15  Martin Jambor  <mjambor@suse.cz>

        PR middle-end/45644
        * tree-sra.c (create_access): Check for bit-fields directly.

        * testsuite/gcc.dg/ipa/pr45644.c: New test.
* testsuite/g++.dg/ipa/pr51759.C: Likewise.

From-SVN: r183023

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ipa/pr51759.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/ipa/pr45644.c [new file with mode: 0644]
gcc/tree-sra.c

index 66cf0914da4f7a1ff14615224567e990c7ad2346..a3752928d7d780e3de95251e95ae681488d5cdca 100644 (file)
@@ -1,3 +1,12 @@
+2012-01-09  Martin Jambor  <mjambor@suse.cz>
+
+       PR tree-optimization/51759
+       Backport from mainline
+       2010-09-15  Martin Jambor  <mjambor@suse.cz>
+
+        PR middle-end/45644
+        * tree-sra.c (create_access): Check for bit-fields directly.
+
 2012-01-09  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/sparc/sol2-unwind.h (sparc64_is_sighandler): Check that the
index 4b780419d55358f9e9d1e0bc921e48db23d8015e..6d23a5afd4bccdd2899ddc10300d0fa911b927b9 100644 (file)
@@ -1,3 +1,9 @@
+2012-01-09  Martin Jambor  <mjambor@suse.cz>
+
+       PR tree-optimization/51759
+        * gcc.dg/ipa/pr45644.c: New test.
+       * g++.dg/ipa/pr51759.C: Likewise.
+
 2012-01-06  Richard Sandiford  <richard.sandiford@linaro.org>
 
        PR middle-end/48660
diff --git a/gcc/testsuite/g++.dg/ipa/pr51759.C b/gcc/testsuite/g++.dg/ipa/pr51759.C
new file mode 100644 (file)
index 0000000..accfaf2
--- /dev/null
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-options "-O2"  } */
+
+extern "C" void abort (void);
+struct S
+{
+  void __attribute__((noinline)) set(unsigned val)
+    {
+      data = val;
+      if (data != val)
+        abort ();
+    }
+  int pad0;
+  unsigned pad1 : 8;
+  unsigned data : 24;
+  int pad2;
+};
+int main()
+{
+  S s;
+  s.pad2 = -1;
+  s.set(0);
+  if (s.pad2 != -1)
+    abort ();
+}
+
diff --git a/gcc/testsuite/gcc.dg/ipa/pr45644.c b/gcc/testsuite/gcc.dg/ipa/pr45644.c
new file mode 100644 (file)
index 0000000..3f61b8b
--- /dev/null
@@ -0,0 +1,35 @@
+/* Verify that we do not IPA-SRA bitfields.  */
+/* { dg-do run } */
+/* { dg-options "-O2"  } */
+
+extern void abort (void);
+
+struct S
+{
+  int j : 8;
+  int i : 24;
+  int l;
+};
+
+static int __attribute__((noinline)) foo (struct S *s)
+{
+  int z = s->i;
+  if (z != 777)
+    abort ();
+  return 0;
+}
+
+int __attribute__((noinline)) bar (struct S *s)
+{
+  return foo (s);
+}
+
+int main (int argc, char *argv[])
+{
+  struct S s;
+  s.j = 5;
+  s.i = 777;
+  s.l = -1;
+
+  return bar (&s);
+}
index 3326582814ab7618b69062e8c5c000ca21ed2643..c48ee62686dea5df410ffc0240e158da28f4beec 100644 (file)
@@ -771,12 +771,13 @@ create_access (tree expr, gimple stmt, bool write)
          disqualify_candidate (base, "Encountered a variable sized access.");
          return NULL;
        }
-      if ((offset % BITS_PER_UNIT) != 0 || (size % BITS_PER_UNIT) != 0)
+      if (TREE_CODE (expr) == COMPONENT_REF
+         && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
        {
-         disqualify_candidate (base,
-                               "Encountered an acces not aligned to a byte.");
+         disqualify_candidate (base, "Encountered a bit-field access.");
          return NULL;
        }
+      gcc_assert ((offset % BITS_PER_UNIT) == 0);
 
       if (ptr)
        mark_parm_dereference (base, offset + size, stmt);