re PR c/83989 (-Wrestrict false positive with malloc-style functions)
authorJakub Jelinek <jakub@redhat.com>
Fri, 26 Jan 2018 11:47:11 +0000 (12:47 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 26 Jan 2018 11:47:11 +0000 (12:47 +0100)
PR c/83989
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Don't
use SSA_NAME_VAR as base for SSA_NAMEs with non-NULL SSA_NAME_VAR.

* c-c++-common/Wrestrict-3.c: New test.

From-SVN: r257086

gcc/ChangeLog
gcc/gimple-ssa-warn-restrict.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wrestrict-3.c [new file with mode: 0644]

index b6052fc3d74809be15eeb61300c3c2150e01efa1..32fb7baf5912fc764d70c792b458e885d5c9ed2b 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/83989
+       * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Don't
+       use SSA_NAME_VAR as base for SSA_NAMEs with non-NULL SSA_NAME_VAR.
+
 2018-01-26  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * config/arc/arc-arch.h (arc_tune_attr): Add ARC_TUNE_CORE_3.
index d3e4e5242a48ba804452e904d875ab6a75dac04c..5b3b96913132a7b8e796674e62456a973366798a 100644 (file)
@@ -373,9 +373,6 @@ builtin_memref::builtin_memref (tree expr, tree size)
                  offrange[1] += off;
                }
            }
-
-       if (TREE_CODE (base) == SSA_NAME && SSA_NAME_VAR (base))
-         base = SSA_NAME_VAR (base);
       }
 
   if (size)
index 741e538f5e735e483f9bbf23e586273344e57dce..c484d5b7ffeee28c38d9a1c497cd62da46df6bc0 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-26  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/83989
+       * c-c++-common/Wrestrict-3.c: New test.
+
 2018-01-26  Claudiu Zissulescu  <claziss@synopsys.com>
 
        * testsuite/gcc.target/arc/tdelegitimize_addr.c: New test.
diff --git a/gcc/testsuite/c-c++-common/Wrestrict-3.c b/gcc/testsuite/c-c++-common/Wrestrict-3.c
new file mode 100644 (file)
index 0000000..30fc54e
--- /dev/null
@@ -0,0 +1,48 @@
+/* PR c/83989 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wrestrict" } */
+
+__attribute__((__malloc__)) extern void *my_malloc (__SIZE_TYPE__);
+void baz (void *);
+
+#define SIZE 32
+
+void
+foo (void)
+{
+  void *recmem = __builtin_malloc (SIZE);
+  baz (recmem);
+  while (1)
+    {
+      void *oldrecmem = recmem;
+      recmem = __builtin_malloc (SIZE);
+      if (!recmem)
+       {
+         __builtin_free (oldrecmem);
+         return;
+       }
+      __builtin_memcpy (recmem, oldrecmem, SIZE);      /* { dg-bogus "accessing" } */
+      baz (recmem);
+      __builtin_free (oldrecmem);
+    }
+}
+
+void
+bar (void)
+{
+  void *recmem = my_malloc (SIZE);
+  baz (recmem);
+  while (1)
+    {
+      void *oldrecmem = recmem;
+      recmem = my_malloc (SIZE);
+      if (!recmem)
+       {
+         __builtin_free (oldrecmem);
+         return;
+       }
+      __builtin_memcpy (recmem, oldrecmem, SIZE);      /* { dg-bogus "accessing" } */
+      baz (recmem);
+      __builtin_free (oldrecmem);
+    }
+}