re PR tree-optimization/63841 (Incorrect strlen optimization after complete unroll)
authorTeresa Johnson <tejohnson@google.com>
Thu, 13 Nov 2014 15:36:48 +0000 (15:36 +0000)
committerTeresa Johnson <tejohnson@gcc.gnu.org>
Thu, 13 Nov 2014 15:36:48 +0000 (15:36 +0000)
2014-11-13  Teresa Johnson  <tejohnson@google.com>

gcc:
PR tree-optimization/63841
* tree.c (initializer_zerop): A clobber does not zero initialize.

gcc/testsuite:
PR tree-optimization/63841
* g++.dg/tree-ssa/pr63841.C: New test.

From-SVN: r217505

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/pr63841.C [new file with mode: 0644]
gcc/tree.c

index dca1d5a..c6014e9 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-13  Teresa Johnson  <tejohnson@google.com>
+
+       PR tree-optimization/63841
+       * tree.c (initializer_zerop): A clobber does not zero initialize.
+
 2014-11-13  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
        * optabs.c (prepare_operand): Gracefully fail if the mode of X
index 279c1b4..b4484b6 100644 (file)
@@ -1,3 +1,7 @@
+2014-11-13  Teresa Johnson  <tejohnson@google.com>
+       PR tree-optimization/63841
+       * g++.dg/tree-ssa/pr63841.C: New test.
+
 2014-11-13  Richard Biener  <rguenther@suse.de>
 
        * gcc.dg/tree-ssa/forwprop-28.c: Adjust.
diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr63841.C b/gcc/testsuite/g++.dg/tree-ssa/pr63841.C
new file mode 100644 (file)
index 0000000..466e320
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include <cstdio>
+#include <string>
+
+std::string __attribute__ ((noinline)) comp_test_write() {
+  std::string data;
+
+  for (int i = 0; i < 2; ++i) {
+    char b = 1 >> (i * 8);
+    data.append(&b, 1);
+  }
+
+  return data;
+}
+
+std::string __attribute__ ((noinline)) comp_test_write_good() {
+  std::string data;
+
+  char b;
+  for (int i = 0; i < 2; ++i) {
+    b = 1 >> (i * 8);
+    data.append(&b, 1);
+  }
+
+  return data;
+}
+
+int main() {
+  std::string good = comp_test_write_good();
+  printf("expected: %hx\n", *(short*)good.c_str());
+
+  std::string bad = comp_test_write();
+  printf("got: %hx\n", *(short*)bad.c_str());
+
+  return good != bad;
+}
index 221f0dd..cf37a19 100644 (file)
@@ -10330,6 +10330,8 @@ initializer_zerop (const_tree init)
       {
        unsigned HOST_WIDE_INT idx;
 
+       if (TREE_CLOBBER_P (init))
+         return false;
        FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), idx, elt)
          if (!initializer_zerop (elt))
            return false;