From: Jakub Jelinek Date: Fri, 26 Jan 2018 11:47:11 +0000 (+0100) Subject: re PR c/83989 (-Wrestrict false positive with malloc-style functions) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=79fbdeb87e6e91a8179465ea56007e493c7ca751;p=gcc.git re PR c/83989 (-Wrestrict false positive with malloc-style functions) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b6052fc3d74..32fb7baf591 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-01-26 Jakub Jelinek + + 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 * config/arc/arc-arch.h (arc_tune_attr): Add ARC_TUNE_CORE_3. diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index d3e4e5242a4..5b3b9691313 100644 --- a/gcc/gimple-ssa-warn-restrict.c +++ b/gcc/gimple-ssa-warn-restrict.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 741e538f5e7..c484d5b7ffe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-26 Jakub Jelinek + + PR c/83989 + * c-c++-common/Wrestrict-3.c: New test. + 2018-01-26 Claudiu Zissulescu * 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 index 00000000000..30fc54e12b7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wrestrict-3.c @@ -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); + } +}