🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #80

fold-const.c contains an integer overflow (GCC 2.3.1)

#80
From: Paul Eggert
Date: Thu, 05 Nov 1992 02:02
36 lines
1844 bytes
Here is a patch to a typo in fold-const.c (GCC 2.3.1, sparc).  On a sparc, the
expression (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1) evaluates to
1<<31, which is a signed integer overflow.  Replacing it with (-1)<<31 fixes
the problem.

This is the only constant expression signed integer overflow that I found in
GCC 2.3.1 itself (sparc, SunOS 4.1.2).

Thu Nov  5 01:53:38 1992  Paul Eggert  (eggert@twinsun.com)

	* fold-const.c (fold_convert): Avoid signed integer overflow in 1<<N.

===================================================================
RCS file: fold-const.c,v
retrieving revision 2.3.1.5
retrieving revision 2.3.1.6
diff -c -r2.3.1.5 -r2.3.1.6
*** fold-const.c	1992/11/05 01:27:21	2.3.1.5
--- fold-const.c	1992/11/05 01:53:38	2.3.1.6
***************
*** 1530,1536 ****
  	    if (d >= (REAL_VALUE_TYPE) half_word * half_word / 2)
  	      {
  		low = d - (REAL_VALUE_TYPE) half_word * half_word / 2;
! 		low |= (HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1);
  	      }
  	    else
  	      low = (HOST_WIDE_INT) d;
--- 1530,1536 ----
  	    if (d >= (REAL_VALUE_TYPE) half_word * half_word / 2)
  	      {
  		low = d - (REAL_VALUE_TYPE) half_word * half_word / 2;
! 		low |= (HOST_WIDE_INT) -1 << (HOST_BITS_PER_WIDE_INT - 1);
  	      }
  	    else
  	      low = (HOST_WIDE_INT) d;
Technical Details
Message-ID: <9211050202.AA14073@farside.twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
From: eggert@twinsun.COM (Paul Eggert)
Subject: fold-const.c contains an integer overflow (GCC 2.3.1)
Message-ID: <9211050202.AA14073@farside.twinsun.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Thu, 5 Nov 1992 02:02:02 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 37