public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] cse: avoid signed overflow in compute_const_anchors [PR 104843]
@ 2022-03-09 11:19 Xi Ruoyao
  2022-03-09 14:55 ` Richard Biener
  0 siblings, 1 reply; 6+ messages in thread
From: Xi Ruoyao @ 2022-03-09 11:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Sandiford, Jeff Law

Bootstrapped and tested on mips64el-linux-gnuabi64, and MIPS is the only
port with a non-zero targetm.const_anchor.  Ok for trunk?

-- >8 --

With a non-zero const_anchor, the behavior of this function relied on
signed overflow.

gcc/

	PR rtl-optimization/104843
	* cse.cc (compute_const_anchors): Cast to unsigned HOST_WIDE_INT
	to perform overflow arithmetics safely.
---
 gcc/cse.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cse.cc b/gcc/cse.cc
index a18b599d324..7c39a009449 100644
--- a/gcc/cse.cc
+++ b/gcc/cse.cc
@@ -1169,10 +1169,10 @@ compute_const_anchors (rtx cst,
 		       HOST_WIDE_INT *lower_base, HOST_WIDE_INT *lower_offs,
 		       HOST_WIDE_INT *upper_base, HOST_WIDE_INT *upper_offs)
 {
-  HOST_WIDE_INT n = INTVAL (cst);
+  unsigned HOST_WIDE_INT n = INTVAL (cst);
 
   *lower_base = n & ~(targetm.const_anchor - 1);
-  if (*lower_base == n)
+  if (*lower_base == INTVAL (cst))
     return false;
 
   *upper_base =
-- 
2.35.1



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

end of thread, other threads:[~2022-03-11 11:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-09 11:19 [PATCH] cse: avoid signed overflow in compute_const_anchors [PR 104843] Xi Ruoyao
2022-03-09 14:55 ` Richard Biener
2022-03-09 16:12   ` [PATCH v2] " Xi Ruoyao
2022-03-10  8:01     ` Richard Biener
2022-03-10 11:32       ` Xi Ruoyao
2022-03-11 11:12         ` Richard Biener

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