public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: weixiangyu <weixiangyu@huawei.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: James Greenhalgh <james.greenhalgh@arm.com>,
	       "gcc-patches@gcc.gnu.org"	<gcc-patches@gcc.gnu.org>,
	       Marcus Shawcroft <Marcus.Shawcroft@arm.com>,
	       Richard Earnshaw <Richard.Earnshaw@arm.com>,
	       "Yangfei (Felix)"	<felix.yang@huawei.com>
Subject: RE: backport the fixes of PR target/64011 and /61749 to 4.9 gcc
Date: Thu, 11 Jun 2015 12:02:00 -0000	[thread overview]
Message-ID: <894B9D8AA7173E40BFFBBF195B8281BCB76B79@SZXEMI503-MBX.china.huawei.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1506101015080.2077@digraph.polyomino.org.uk>

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

Hi
Patch modified. Use %wu instead of HOST_WIDE_INT_PRINT_UNSIGNED. 
Tested ok on aarch64-linux(big-endian and little-endian) with qemu.

Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog	(revision 223867)
+++ gcc/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2015-06-11  Xiangyu Wei  <weixiangyu@huawei.com>
+
+	Backport from mainline r219717:
+	2015-01-15  Jiong Wang  <jiong.wang@arm.com>
+	PR rtl-optimization/64011
+	* expmed.c (store_bit_field_using_insv): Warn and truncate bitsize when
+	there is partial overflow.
 2015-05-28  Mike Frysinger  <vapier@gentoo.org>
 
 	* config/nios2/linux.h (CPP_SPEC): Define.
Index: gcc/expmed.c
===================================================================
--- gcc/expmed.c	(revision 223867)
+++ gcc/expmed.c	(working copy)
@@ -540,6 +540,21 @@ store_bit_field_using_insv (const extraction_insn
       copy_back = true;
     }
 
+  /* There are similar overflow check at the start of store_bit_field_1, 
+    but that only check the situation where the field lies completely 
+    outside the register, while there do have situation where the field 
+    lies partialy in the register, we need to adjust bitsize for this 
+    partial overflow situation.  Without this fix, pr48335-2.c on big-endian 
+    will broken on those arch support bit insert instruction, like arm, aarch64 
+    etc.  */ 
+  if (bitsize + bitnum > unit && bitnum < unit) 
+    { 
+      warning (OPT_Wextra, "write of %wu-bit data outside the bound of "
+	       "destination object, data truncated into %wu-bit",
+	       bitsize, unit - bitnum);
+      bitsize = unit - bitnum; 
+    }  
+
   /* If BITS_BIG_ENDIAN is zero on a BYTES_BIG_ENDIAN machine, we count
      "backwards" from the size of the unit we are inserting into.
      Otherwise, we count bits from the most significant on a

Thanks!
XIangyu Wei

-----Original Message-----
From: Joseph Myers [mailto:joseph@codesourcery.com] 
Sent: Wednesday, June 10, 2015 6:18 PM
To: weixiangyu
Cc: James Greenhalgh; gcc-patches@gcc.gnu.org; Marcus Shawcroft; Richard Earnshaw; Richard Earnshaw
Subject: RE: backport the fixes of PR target/64011 and /61749 to 4.9 gcc

On Wed, 10 Jun 2015, weixiangyu wrote:

> +  if (bitsize + bitnum > unit && bitnum < unit) 
> +    { 
> +      warning (OPT_Wextra, "write of "HOST_WIDE_INT_PRINT_UNSIGNED"bit data " 
> +               "outside the bound of destination object, data truncated into " 
> +               HOST_WIDE_INT_PRINT_UNSIGNED"bit", bitsize, unit - 
> + bitnum);

HOST_WIDE_INT_PRINT_UNSIGNED is a printf format, which depends on the host and is not suitable for any translatable string, not a format for GCC's pretty printers.  Use %wu instead in any call to a GCC diagnostic function.  Mainline appears to have this correct.

--
Joseph S. Myers
joseph@codesourcery.com

[-- Attachment #2: pr64011_v2.diff --]
[-- Type: application/octet-stream, Size: 1736 bytes --]

Index: gcc/ChangeLog
===================================================================
--- gcc/ChangeLog	(revision 223867)
+++ gcc/ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2015-06-11  Xiangyu Wei  <weixiangyu@huawei.com>
+
+	Backport from mainline r219717:
+	2015-01-15  Jiong Wang  <jiong.wang@arm.com>
+	PR rtl-optimization/64011
+	* expmed.c (store_bit_field_using_insv): Warn and truncate bitsize when
+	there is partial overflow.
 2015-05-28  Mike Frysinger  <vapier@gentoo.org>
 
 	* config/nios2/linux.h (CPP_SPEC): Define.
Index: gcc/expmed.c
===================================================================
--- gcc/expmed.c	(revision 223867)
+++ gcc/expmed.c	(working copy)
@@ -540,6 +540,21 @@ store_bit_field_using_insv (const extraction_insn
       copy_back = true;
     }
 
+  /* There are similar overflow check at the start of store_bit_field_1, 
+    but that only check the situation where the field lies completely 
+    outside the register, while there do have situation where the field 
+    lies partialy in the register, we need to adjust bitsize for this 
+    partial overflow situation.  Without this fix, pr48335-2.c on big-endian 
+    will broken on those arch support bit insert instruction, like arm, aarch64 
+    etc.  */ 
+  if (bitsize + bitnum > unit && bitnum < unit) 
+    { 
+      warning (OPT_Wextra, "write of %wu-bit data outside the bound of "
+	       "destination object, data truncated into %wu-bit",
+	       bitsize, unit - bitnum);
+      bitsize = unit - bitnum; 
+    }  
+
   /* If BITS_BIG_ENDIAN is zero on a BYTES_BIG_ENDIAN machine, we count
      "backwards" from the size of the unit we are inserting into.
      Otherwise, we count bits from the most significant on a

  reply	other threads:[~2015-06-11 11:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27  5:28 weixiangyu
2015-05-28 14:09 ` James Greenhalgh
2015-06-10  3:26   ` weixiangyu
2015-06-10 10:44     ` Joseph Myers
2015-06-11 12:02       ` weixiangyu [this message]
2015-06-11  9:35     ` Marcus Shawcroft
2015-06-12 11:11       ` weixiangyu

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=894B9D8AA7173E40BFFBBF195B8281BCB76B79@SZXEMI503-MBX.china.huawei.com \
    --to=weixiangyu@huawei.com \
    --cc=Marcus.Shawcroft@arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=felix.yang@huawei.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=james.greenhalgh@arm.com \
    --cc=joseph@codesourcery.com \
    /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).