public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bernd Schmidt <bschmidt@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Fix PR77880
Date: Fri, 07 Oct 2016 12:18:00 -0000	[thread overview]
Message-ID: <cbc378b0-c2d2-1ed0-70c9-50558e31746a@redhat.com> (raw)

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

When encountering a memcmp with something like ULONG_MAX for the size, a 
calculation can overflow in by_pieces_ninsns because it uses int rather 
than HOST_WIDE_INT.

Bootstrapped & tested on x86_64-linux, committed as obvious.


Bernd


[-- Attachment #2: bypieces.diff --]
[-- Type: text/x-patch, Size: 925 bytes --]

Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog	(revision 240861)
+++ gcc/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2016-10-07  Bernd Schmidt  <bschmidt@redhat.com>
+
+	PR tree-optimization/77880
+	* expr.c (by_pieces_ninsns): Use unsigned HOST_WIDE_INT where
+	necessary.
+
 2016-10-07  Marek Polacek  <polacek@redhat.com>
 
 	PR c++/77803
Index: gcc/expr.c
===================================================================
--- gcc/expr.c	(revision 240861)
+++ gcc/expr.c	(working copy)
@@ -785,7 +785,7 @@ by_pieces_ninsns (unsigned HOST_WIDE_INT
 	    case COMPARE_BY_PIECES:
 	      int batch = targetm.compare_by_pieces_branch_ratio (mode);
 	      int batch_ops = 4 * batch - 1;
-	      int full = n_pieces / batch;
+	      unsigned HOST_WIDE_INT full = n_pieces / batch;
 	      n_insns += full * batch_ops;
 	      if (n_pieces % batch != 0)
 		n_insns++;

                 reply	other threads:[~2016-10-07 12:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=cbc378b0-c2d2-1ed0-70c9-50558e31746a@redhat.com \
    --to=bschmidt@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).