Use array_at_struct_end_p in tree-chkp.c (PR middle-end/68270).
authorMartin Liska <mliska@suse.cz>
Tue, 7 Mar 2017 14:12:52 +0000 (15:12 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 7 Mar 2017 14:12:52 +0000 (14:12 +0000)
2017-03-07  Martin Liska  <mliska@suse.cz>

PR middle-end/68270
* tree-chkp.c (chkp_may_narrow_to_field): Add new argument ref.
Use array_at_struct_end_p instead of DECL_CHAIN (field).
(chkp_narrow_bounds_for_field): Likewise.
(chkp_parse_array_and_component_ref): Pass one more argument to
call.
2017-03-07  Martin Liska  <mliska@suse.cz>

PR middle-end/68270
* g++.dg/pr68270.C: New test.

From-SVN: r245951

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr68270.C [new file with mode: 0644]
gcc/tree-chkp.c

index c1b71bc432e9ff7393de69f5208463db53a7d29c..ecbafb445da2196b7d854a856550d16abb2b222c 100644 (file)
@@ -1,3 +1,12 @@
+2017-03-07  Martin Liska  <mliska@suse.cz>
+
+       PR middle-end/68270
+       * tree-chkp.c (chkp_may_narrow_to_field): Add new argument ref.
+       Use array_at_struct_end_p instead of DECL_CHAIN (field).
+       (chkp_narrow_bounds_for_field): Likewise.
+       (chkp_parse_array_and_component_ref): Pass one more argument to
+       call.
+
 2017-03-07  Richard Biener  <rguenther@suse.de>
 
        * tree-vect-loop-manip.c (slpeel_add_loop_guard): Preserve
index b927b5a2976279644208f673eeb5e7c5031332ca..932e792bd75ced623459074b22cab5fe84e11d3b 100644 (file)
@@ -1,3 +1,8 @@
+2017-03-07  Martin Liska  <mliska@suse.cz>
+
+       PR middle-end/68270
+       * g++.dg/pr68270.C: New test.
+
 2017-03-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/79901
diff --git a/gcc/testsuite/g++.dg/pr68270.C b/gcc/testsuite/g++.dg/pr68270.C
new file mode 100644 (file)
index 0000000..441fca3
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR71633 */
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && { ! x32 } } } } */
+/* { dg-options "-Werror=chkp -mmpx -fcheck-pointer-bounds -O1 -fchkp-flexible-struct-trailing-arrays" } */
+
+struct a
+{
+  struct
+  {
+    int e[1];
+  } f;
+};
+
+int g(a *ptr)
+{
+  return ptr->f.e[1];
+}
index 02ae2d2d2c79f8dc3c5d7a6a2b689a70ff816130..b7b412efcef7bdf622ff089e8c2aebe30232cd96 100644 (file)
@@ -3266,15 +3266,15 @@ chkp_intersect_bounds (tree bounds1, tree bounds2, gimple_stmt_iterator *iter)
 }
 
 /* Return 1 if we are allowed to narrow bounds for addressed FIELD
-   and 0 othersize.  */
+   and 0 othersize.  REF is reference to the field.  */
+
 static bool
-chkp_may_narrow_to_field (tree field)
+chkp_may_narrow_to_field (tree ref, tree field)
 {
   return DECL_SIZE (field) && TREE_CODE (DECL_SIZE (field)) == INTEGER_CST
     && tree_to_uhwi (DECL_SIZE (field)) != 0
     && !(flag_chkp_flexible_struct_trailing_arrays
-        && TREE_CODE(TREE_TYPE(field)) == ARRAY_TYPE
-        && !DECL_CHAIN (field))
+        && array_at_struct_end_p (ref, true))
     && (!DECL_FIELD_OFFSET (field)
        || TREE_CODE (DECL_FIELD_OFFSET (field)) == INTEGER_CST)
     && (!DECL_FIELD_BIT_OFFSET (field)
@@ -3284,14 +3284,15 @@ chkp_may_narrow_to_field (tree field)
 }
 
 /* Return 1 if bounds for FIELD should be narrowed to
-   field's own size.  */
+   field's own size.  REF is reference to the field.  */
+
 static bool
-chkp_narrow_bounds_for_field (tree field)
+chkp_narrow_bounds_for_field (tree ref, tree field)
 {
   HOST_WIDE_INT offs;
   HOST_WIDE_INT bit_offs;
 
-  if (!chkp_may_narrow_to_field (field))
+  if (!chkp_may_narrow_to_field (ref, field))
     return false;
 
   /* Accesse to compiler generated fields should not cause
@@ -3428,7 +3429,8 @@ chkp_parse_array_and_component_ref (tree node, tree *ptr,
          if (flag_chkp_narrow_bounds
              && !flag_chkp_narrow_to_innermost_arrray
              && (!last_comp
-                 || chkp_may_narrow_to_field (TREE_OPERAND (last_comp, 1))))
+                 || chkp_may_narrow_to_field (var,
+                                              TREE_OPERAND (last_comp, 1))))
            {
              comp_to_narrow = last_comp;
              break;
@@ -3440,7 +3442,7 @@ chkp_parse_array_and_component_ref (tree node, tree *ptr,
 
          if (innermost_bounds
              && !array_ref_found
-             && chkp_narrow_bounds_for_field (field))
+             && chkp_narrow_bounds_for_field (var, field))
            comp_to_narrow = var;
          last_comp = var;