public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix UBSAN errors in dse.c (PR rtl-optimization/82044).
@ 2017-09-20  7:51 Martin Liška
  2017-09-20  8:15 ` Jakub Jelinek
  0 siblings, 1 reply; 14+ messages in thread
From: Martin Liška @ 2017-09-20  7:51 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 546 bytes --]

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(-)



[-- Attachment #2: 0001-Fix-UBSAN-errors-in-dse.c-PR-rtl-optimization-82044.patch --]
[-- Type: text/x-patch, Size: 1263 bytes --]

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-12-19 11:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20  7:51 [PATCH] Fix UBSAN errors in dse.c (PR rtl-optimization/82044) Martin Liška
2017-09-20  8:15 ` Jakub Jelinek
2017-10-19 11:58   ` Martin Liška
2017-11-02 13:15     ` Martin Liška
2017-11-08 16:42       ` Jeff Law
2017-11-15  7:34         ` Martin Liška
2017-11-17  0:57           ` Jeff Law
2017-11-22  0:27           ` [PATCH] Fix i?86 bootstrap " Jakub Jelinek
2017-11-22  8:01             ` Jakub Jelinek
2017-11-22  9:00               ` Richard Biener
2017-11-22  9:11                 ` Richard Biener
2017-12-19 11:26                   ` Martin Liška
2017-11-22  9:45             ` Eric Botcazou
2017-11-22  9:52               ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).