This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use array_at_struct_end_p in tree-chkp.c (PR middle-end/68270).


Hello.

As mentioned by Richard ([1]), the function should be used instead of
DECL_CHAIN(..) checking.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin


[1] https://gcc.gnu.org/ml/gcc-patches/2017-01/msg00172.html
>From 617a2c5dea8895be593ba0ac68e0b6d038943af3 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 3 Mar 2017 14:22:23 +0100
Subject: [PATCH] Use array_at_struct_end_p in tree-chkp.c (PR
 middle-end/68270).

gcc/ChangeLog:

2017-03-03  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.

gcc/testsuite/ChangeLog:

2017-03-03  Martin Liska  <mliska@suse.cz>

	PR middle-end/68270
	* g++.dg/pr68270.C: New test.
---
 gcc/testsuite/g++.dg/pr68270.C | 16 ++++++++++++++++
 gcc/tree-chkp.c                | 20 +++++++++++---------
 2 files changed, 27 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/pr68270.C

diff --git a/gcc/testsuite/g++.dg/pr68270.C b/gcc/testsuite/g++.dg/pr68270.C
new file mode 100644
index 00000000000..441fca3e85f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr68270.C
@@ -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];
+}
diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 02ae2d2d2c7..b7b412efcef 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -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;
 
-- 
2.11.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]