Add new test for PR tree-optimization/92982.
authorMartin Sebor <msebor@redhat.com>
Mon, 2 Mar 2020 18:49:01 +0000 (11:49 -0700)
committerMartin Sebor <msebor@redhat.com>
Mon, 2 Mar 2020 18:49:01 +0000 (11:49 -0700)
gcc/testsuite/ChangeLog:
PR tree-optimization/92982
* gcc.dg/strlenopt-94.c: New test.

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/strlenopt-94.c [new file with mode: 0644]

index 79fe37d5a179c749866767a10ff8978c6b4f4233..e18c6a9f7a675fd7a65baff4353c9b1cd2c938e3 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-02  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/92982
+       * gcc.dg/strlenopt-94.c: New test.
+
 2020-03-02  Iain Sandoe  <iain@sandoe.co.uk>
 
        * g++.dg/coroutines/torture/func-params-09-awaitable-parms.C: New test.
diff --git a/gcc/testsuite/gcc.dg/strlenopt-94.c b/gcc/testsuite/gcc.dg/strlenopt-94.c
new file mode 100644 (file)
index 0000000..c2a23d3
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR tree-optimization/93982 - Assignment incorrectly omitted by
+   -foptimize-strlen
+   { dg-do run }
+   { dg-options "-O2 -Wall" } */
+
+struct A { const char **a; };
+const char *buf[5];
+
+__attribute__((noipa)) struct A
+foo (char *p)
+{
+  struct A r = { (const char **) p };
+  r.a[0] = "12345678";
+  r.a[1] = "";
+  r.a[2] = "";
+  r.a[3] = "";
+  r.a[4] = "";
+  return r;
+}
+
+int
+main ()
+{
+  struct A r = foo ((char *) &buf[0]);
+  if (!r.a[1] || r.a[1][0] != '\0')
+    __builtin_abort ();
+  return 0;
+}