public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: Jeff Law <law@redhat.com>, gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix i?86 bootstrap (PR rtl-optimization/82044)
Date: Wed, 22 Nov 2017 00:27:00 -0000	[thread overview]
Message-ID: <20171121232720.GD14653@tucnak> (raw)
In-Reply-To: <87d09716-916c-974f-9a4e-7fa95f6b97c3@suse.cz>

Hi!

On Wed, Nov 15, 2017 at 08:31:00AM +0100, Martin Liška wrote:
> On 11/08/2017 05:31 PM, Jeff Law wrote:
> > I don't see an updated patch in this thread?  THe last message I see is
> > this one where you indicate you're going to tweak the patch and re-test.
> > 
> > Jeff
> 
> Yes, I tweaked and tested following patch.
> 
> Martin

> >From a369ac78b887e219a375e17d6817c1f744e71779 Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Thu, 19 Oct 2017 13:38:01 +0200
> Subject: [PATCH] Fix UBSAN errors in dse.c (PR rtl-optimization/82044).
> 
> gcc/ChangeLog:
> 
> 2017-10-19  Martin Liska  <mliska@suse.cz>
> 
> 	PR rtl-optimization/82044
> 	PR tree-optimization/82042
> 	* dse.c (check_mem_read_rtx): Check for overflow.

Unfortunately this patch broke i686-linux bootstrap, during stage2
libgcc configure fails due to numerous ICEs.

There are 2 problems with the patch:
1) if the mode of the read is BLKmode, then width is set to -1,
so offset > HOST_WIDE_INT_MAX - width invokes UB at compile time
and is true for any offset > HOST_WIDE_INT_MIN if the compiler wraps
the result around.
2) clear_rhs_from_active_local_stores () is the punt action in record_store,
but not in check_mem_read_rtx, where e.g. a few lines above it if
canon_address fails it does add_wild_read instead.

The following patch fixes those two issues and adds similar overflow
check to record_store too (in that spot width is always non-negative, so
we don't need a special width == -1 handling).

Bootstrapped successfully on i686-linux, ok for trunk if it passes regtest
there (and pending x86_64-linux bootstrap + regtest)?

2017-11-21  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/82044
	PR tree-optimization/82042
	* dse.c (record_store): Check for overflow.
	(check_mem_read_rtx): Properly check for overflow if width == -1, call
	add_wild_read instead of clear_rhs_from_active_local_stores on
	overflow and log it into dump_file.

--- gcc/dse.c.jj	2017-11-21 23:18:18.000000000 +0100
+++ gcc/dse.c	2017-11-21 23:28:08.952439915 +0100
@@ -1342,6 +1342,12 @@ record_store (rtx body, bb_info_t bb_inf
   else
     width = GET_MODE_SIZE (GET_MODE (mem));
 
+  if (offset > HOST_WIDE_INT_MAX - width)
+    {
+      clear_rhs_from_active_local_stores ();
+      return 0;
+    }
+
   if (group_id >= 0)
     {
       /* In the restrictive case where the base is a constant or the
@@ -1981,9 +1987,13 @@ check_mem_read_rtx (rtx *loc, bb_info_t
   else
     width = GET_MODE_SIZE (GET_MODE (mem));
 
-  if (offset > HOST_WIDE_INT_MAX - width)
+  if (width == -1
+      ? offset == HOST_WIDE_INT_MIN
+      : offset > HOST_WIDE_INT_MAX - width)
     {
-      clear_rhs_from_active_local_stores ();
+      if (dump_file && (dump_flags & TDF_DETAILS))
+	fprintf (dump_file, " adding wild read, due to overflow.\n");
+      add_wild_read (bb_info);
       return;
     }
 


	Jakub

  parent reply	other threads:[~2017-11-21 23:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-20  7:51 [PATCH] Fix UBSAN errors in dse.c " 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           ` Jakub Jelinek [this message]
2017-11-22  8:01             ` [PATCH] Fix i?86 bootstrap " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171121232720.GD14653@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).