]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/63841 (Incorrect strlen optimization after complete...
authorTeresa Johnson <tejohnson@google.com>
Tue, 18 Nov 2014 14:20:58 +0000 (14:20 +0000)
committerTeresa Johnson <tejohnson@gcc.gnu.org>
Tue, 18 Nov 2014 14:20:58 +0000 (14:20 +0000)
2014-11-18  Teresa Johnson  <tejohnson@google.com>

Backport from mainline and gcc-4_9 branch.

2014-11-13  Teresa Johnson  <tejohnson@google.com>

PR tree-optimization/63841
* tree-ssa-strlen.c (strlen_optimize_stmt): Ignore clobbers.

2014-11-13  Teresa Johnson  <tejohnson@google.com>

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

From-SVN: r217715

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

index 3bb275bedd636048839e00733cfe67a0393b3924..3bc25c3c2faedfe93fec303cdca7cd4322329f91 100644 (file)
@@ -1,3 +1,11 @@
+2014-11-18  Teresa Johnson  <tejohnson@google.com>
+
+       Backport from mainline and gcc-4_9 branch.
+       2014-11-13  Teresa Johnson  <tejohnson@google.com>
+
+       PR tree-optimization/63841
+       * tree-ssa-strlen.c (strlen_optimize_stmt): Ignore clobbers.
+
 2014-11-16  Eric Botcazou  <ebotcazou@adacore.com>
 
        * doc/tm.texi.in (TARGET_FLAGS_REGNUM): Move around.
index a4c8f412d8475eda32576e430df857f24b4f9cbd..1de0fd49186809fa271f32583c28aa6ece3efb17 100644 (file)
@@ -1,3 +1,11 @@
+2014-11-18  Teresa Johnson  <tejohnson@google.com>
+
+       Backport from mainline and gcc-4_9 branch.
+       2014-11-13  Teresa Johnson  <tejohnson@google.com>
+
+       PR tree-optimization/63841
+       * g++.dg/tree-ssa/pr63841.C: New test.
+
 2014-11-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR ipa/63838
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..2a2c78f
--- /dev/null
@@ -0,0 +1,35 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#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();
+  std::string bad = comp_test_write();
+
+  if (good != bad)
+    __builtin_abort ();
+}
index dbad4a80d867291fc134f1fc1604eef669d781ac..fbd51ec2c980ee77a947df347b2c83e52357cfd6 100644 (file)
@@ -1777,7 +1777,7 @@ strlen_optimize_stmt (gimple_stmt_iterator *gsi)
            break;
          }
     }
-  else if (is_gimple_assign (stmt))
+  else if (is_gimple_assign (stmt) && !gimple_clobber_p (stmt))
     {
       tree lhs = gimple_assign_lhs (stmt);