https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94015

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Nate Eldredge from comment #4)
> I'm not qualified to opine on the proposed fix, but just wanted to note
> that, as I mentioned above, running your testcase doesn't actually exercise
> the bug on amd64/linux because the high byte of the address of the literal
> is always zero, so the test passes whether s[7]='\0' is "optimized" out or
> not.  More tests are always good, I suppose, but I just want to emphasize
> that running this testcase is not the way to check whether the bug is fixed.
> I wasn't able to come up with a good runtime way to check whether the code
> was correctly compiled.  Maybe someone more clever than me can think of a
> way?

Yes, I've tested it on powerpc64-linux, where the test FAILs without the fix
and succeeds with it.
Anyway, following adjusted test FAILs even on x86_64-linux without the fix and
succeeds with it:
--- gcc/testsuite/gcc.dg/pr94015.c.jj   2020-03-03 18:04:47.928594261 +0100
+++ gcc/testsuite/gcc.dg/pr94015.c      2020-03-03 18:04:34.345794259 +0100
@@ -0,0 +1,107 @@
+/* PR tree-optimization/94015 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+char buf[10] = "AAAAAAAAA";
+
+__attribute__((noipa)) char *
+alloc (void)
+{
+  return buf;
+}
+
+__attribute__((noipa)) void
+f1 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "1234567";
+  s[7] = '\0';
+}
+
+__attribute__((noipa)) void
+f2 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "123456";
+  s[6] = '\0';
+}
+
+__attribute__((noipa)) void
+f3 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "12345";
+  s[5] = '\0';
+}
+
+__attribute__((noipa)) void
+f4 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "1234";
+  s[4] = '\0';
+}
+
+__attribute__((noipa)) void
+f5 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "123";
+  s[3] = '\0';
+}
+
+__attribute__((noipa)) void
+f6 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "12";
+  s[2] = '\0';
+}
+
+__attribute__((noipa)) void
+f7 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "1";
+  s[1] = '\0';
+}
+
+__attribute__((noipa)) void
+f8 (void)
+{
+  char *s = alloc ();
+  *(char **)s = "";
+  s[0] = '\0';
+}
+
+int
+main ()
+{
+  if (sizeof (char *) > 8)
+    return 0;
+  f1 ();
+  if (buf[7] != 0)
+    __builtin_abort ();
+  f2 ();
+  if (buf[6] != 0)
+    __builtin_abort ();
+  f3 ();
+  if (buf[5] != 0)
+    __builtin_abort ();
+  f4 ();
+  if (buf[4] != 0)
+    __builtin_abort ();
+  f5 ();
+  if (buf[3] != 0)
+    __builtin_abort ();
+  f6 ();
+  if (buf[2] != 0)
+    __builtin_abort ();
+  f7 ();
+  if (buf[1] != 0)
+    __builtin_abort ();
+  f8 ();
+  if (buf[0] != 0)
+    __builtin_abort ();
+  return 0;
+}

Reply via email to