]> gcc.gnu.org Git - gcc.git/commitdiff
gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): For an ADDR_EXPR, do...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 16 Jan 2018 23:11:10 +0000 (23:11 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 16 Jan 2018 23:11:10 +0000 (23:11 +0000)
* 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

gcc/ChangeLog
gcc/gimple-ssa-warn-restrict.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Warray-bounds-3.c

index a4fa75c773fe0d92128b0d29b46c8214bfe7b966..66fd97ed2de397da185d0a57b4d95f2290c98621 100644 (file)
@@ -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
index 6979403a4f492791d6f61cec2cc784841e40c7b2..d3e4e5242a48ba804452e904d875ab6a75dac04c 100644 (file)
@@ -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
        {
index a6933d29b96e24c08bd43161238924b3486e95f8..a4fc221f136cbe07a15e731116122e8f285ad5ad 100644 (file)
@@ -1,3 +1,7 @@
+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
index eb0f05045d59083b32c4601ba784a9a4a647f38e..3445b950811b4429ea971997b0def986ce24805c 100644 (file)
@@ -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]." } */
 }
 
 
This page took 0.186856 seconds and 5 git commands to generate.