aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2018-01-16 23:11:10 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2018-01-16 23:11:10 +0000
commit12b38cca4a25ca8dcda775ebdbcb57e4c622eb0b (patch)
treeb35c60a150370db2798b69a8e8ebc0a4b3109841 /gcc
parent035181c3129648328176cbdee69d2a7a66e0a895 (diff)
downloadgcc-12b38cca4a25ca8dcda775ebdbcb57e4c622eb0b.zip
gcc-12b38cca4a25ca8dcda775ebdbcb57e4c622eb0b.tar.gz
gcc-12b38cca4a25ca8dcda775ebdbcb57e4c622eb0b.tar.bz2
gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): For an ADDR_EXPR, do not count the offset of a COMPONENT_REF twice.
* gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): For an ADDR_EXPR, do not count the offset of a COMPONENT_REF twice. From-SVN: r256766
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/gimple-ssa-warn-restrict.c16
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/c-c++-common/Warray-bounds-3.c3
4 files changed, 16 insertions, 12 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a4fa75c..66fd97e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2018-01-16 Eric Botcazou <ebotcazou@adacore.com>
+
+ * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): For an
+ ADDR_EXPR, do not count the offset of a COMPONENT_REF twice.
+
2018-01-16 Kelvin Nilsen <kelvin@gcc.gnu.org>
* config/rs6000/rs6000-p8swap.c (rs6000_gen_stvx): Generate
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c
index 6979403..d3e4e52 100644
--- a/gcc/gimple-ssa-warn-restrict.c
+++ b/gcc/gimple-ssa-warn-restrict.c
@@ -312,11 +312,11 @@ builtin_memref::builtin_memref (tree expr, tree size)
if (TREE_CODE (expr) == ADDR_EXPR)
{
poly_int64 off;
- tree oper = TREE_OPERAND (expr, 0);
+ tree op = TREE_OPERAND (expr, 0);
/* Determine the base object or pointer of the reference
and its constant offset from the beginning of the base. */
- base = get_addr_base_and_unit_offset (oper, &off);
+ base = get_addr_base_and_unit_offset (op, &off);
HOST_WIDE_INT const_off;
if (base && off.is_constant (&const_off))
@@ -325,17 +325,11 @@ builtin_memref::builtin_memref (tree expr, tree size)
offrange[1] += const_off;
/* Stash the reference for offset validation. */
- ref = oper;
+ ref = op;
/* Also stash the constant offset for offset validation. */
- tree_code code = TREE_CODE (oper);
- if (code == COMPONENT_REF)
- {
- tree field = TREE_OPERAND (ref, 1);
- tree fldoff = DECL_FIELD_OFFSET (field);
- if (TREE_CODE (fldoff) == INTEGER_CST)
- refoff = const_off + wi::to_offset (fldoff);
- }
+ if (TREE_CODE (op) == COMPONENT_REF)
+ refoff = const_off;
}
else
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a6933d2..a4fc221 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2018-01-16 Eric Botcazou <ebotcazou@adacore.com>
+ * c-c++-common/Warray-bounds-3.c (test_memmove_bounds): Fix mismatch.
+
+2018-01-16 Eric Botcazou <ebotcazou@adacore.com>
+
* c-c++-common/Wrestrict.c (test_strcpy_range): Bump string size of one
test and add dg-warning for the -Wstringop-overflow warning.
diff --git a/gcc/testsuite/c-c++-common/Warray-bounds-3.c b/gcc/testsuite/c-c++-common/Warray-bounds-3.c
index eb0f050..3445b95 100644
--- a/gcc/testsuite/c-c++-common/Warray-bounds-3.c
+++ b/gcc/testsuite/c-c++-common/Warray-bounds-3.c
@@ -199,7 +199,8 @@ void test_memmove_bounds (char *d, const char *s, size_t n)
T (int, 2, a + SR ( 1, 3), pi, n);
T (int, 2, a + SR ( 2, 3), pi, n);
- T (int32_t, 2, a + SR ( 3, 4), pi, n); /* { dg-warning "offset \\\[12, 16] is out of the bounds \\\[0, 8] of object .\[^\n\r]+. with type .int32_t ?\\\[2]." } */
+ const int32_t *pi32 = (const int32_t*)s;
+ T (int32_t, 2, a + SR ( 3, 4), pi32, n); /* { dg-warning "offset \\\[12, 16] is out of the bounds \\\[0, 8] of object .\[^\n\r]+. with type .int32_t ?\\\[2]." } */
}