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] Fix UBSAN errors in dse.c (PR rtl-optimization/82044).


Hello.

Following patch handles UBSAN (overflow) in dce.c.

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

Ready to be installed?
Martin

gcc/ChangeLog:

2017-09-11  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/82044
	PR tree-optimization/82042
	* dse.c (set_usage_bits): Check properly for a big offset
	value.
	(record_store): Do not overflow and set maximum value.
	(check_mem_read_rtx): Bail out for a big offset.
---
 gcc/dse.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)


diff --git a/gcc/dse.c b/gcc/dse.c
index cff3ac47356..d519ac70ed5 100644
--- a/gcc/dse.c
+++ b/gcc/dse.c
@@ -929,7 +929,9 @@ set_usage_bits (group_info *group, HOST_WIDE_INT offset, HOST_WIDE_INT width,
 {
   HOST_WIDE_INT i;
   bool expr_escapes = can_escape (expr);
-  if (offset > -MAX_OFFSET && offset + width < MAX_OFFSET)
+  if (offset > -MAX_OFFSET
+      && offset < MAX_OFFSET
+      && offset + width < MAX_OFFSET)
     for (i=offset; i<offset+width; i++)
       {
 	bitmap store1;
@@ -1536,7 +1538,11 @@ record_store (rtx body, bb_info_t bb_info)
     }
   store_info->group_id = group_id;
   store_info->begin = offset;
-  store_info->end = offset + width;
+  if (offset > HOST_WIDE_INT_MAX - width)
+    store_info->end = HOST_WIDE_INT_MAX;
+  else
+    store_info->end = offset + width;
+
   store_info->is_set = GET_CODE (body) == SET;
   store_info->rhs = rhs;
   store_info->const_rhs = const_rhs;
@@ -1976,6 +1982,14 @@ check_mem_read_rtx (rtx *loc, bb_info_t bb_info)
       return;
     }
 
+  if (offset > MAX_OFFSET)
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	fprintf (dump_file, " reaches MAX_OFFSET.\n");
+      add_wild_read (bb_info);
+      return;
+    }
+
   if (GET_MODE (mem) == BLKmode)
     width = -1;
   else


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