From 69ac5e6150ff3db96156a17f93382f9ef9438611 Mon Sep 17 00:00:00 2001 From: ebotcazou Date: Tue, 16 Jan 2018 23:11:10 +0000 Subject: [PATCH] * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): For an ADDR_EXPR, do not count the offset of a COMPONENT_REF twice. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256766 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 +++++ gcc/gimple-ssa-warn-restrict.c | 16 +++++----------- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/c-c++-common/Warray-bounds-3.c | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4fa75c773f..66fd97ed2de 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-01-16 Eric Botcazou + + * 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 * 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 6979403a4f4..d3e4e5242a4 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 a6933d29b96..a4fc221f136 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2018-01-16 Eric Botcazou + * c-c++-common/Warray-bounds-3.c (test_memmove_bounds): Fix mismatch. + +2018-01-16 Eric Botcazou + * 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 eb0f05045d5..3445b950811 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]." } */ } -- 2.11.4.GIT