Article View: gnu.gcc.bug
Article #1389signed char c = 256; long long x = 9223372036854775808ULL; (GCC 2.3.1)
From: Paul Eggert
Date: Thu, 12 Nov 1992 06:39
Date: Thu, 12 Nov 1992 06:39
76 lines
3218 bytes
3218 bytes
GCC 2.3.1 (sparc, SunOS 4.1.2) doesn't catch the signed integer overflows in
either of the following constant expression initializers.
signed char c = 256;
long long x = 9223372036854775808ULL;
The first line isn't diagnosed because force_fit_type yields a nonzero value
that isn't 1, and this value overflows when it is assigned to a 1-bit field.
The second line isn't diagnosed because the overflow occurs as a function of
changing the value from unsigned to signed; force_fit_type can't see this.
Here is a patch. The last hunk of this patch fixes the second bug; the
rest of the patch fixes the first bug.
Thu Nov 12 05:32:24 1992 Paul Eggert (eggert@twinsun.com)
* fold-const.c (force_fit_type): Yield 0 or 1, so that result fits in
a 1-bit field.
(fold-convert): Report an overflow if a large unsigned long long value
converts to a negative signed long long value.
===================================================================
RCS file: fold-const.c,v
retrieving revision 2.3.1.7
retrieving revision 2.3.1.8
diff -c -r2.3.1.7 -r2.3.1.8
*** fold-const.c 1992/11/10 19:20:24 2.3.1.7
--- fold-const.c 1992/11/12 05:32:24 2.3.1.8
***************
*** 117,123 ****
/* Make the integer constant T valid for its type
by setting to 0 or 1 all the bits in the constant
that don't belong in the type.
! Yield nonzero if a signed overflow occurs.
If OVERFLOW is nonzero, a signed overflow has already occurred. */
static int
--- 117,123 ----
/* Make the integer constant T valid for its type
by setting to 0 or 1 all the bits in the constant
that don't belong in the type.
! Yield 1 if a signed overflow occurs, 0 otherwise.
If OVERFLOW is nonzero, a signed overflow has already occurred. */
static int
***************
*** 175,182 ****
/* Yield nonzero if signed overflow occurred. */
return
! (overflow
! | (low ^ TREE_INT_CST_LOW (t)) | (high ^ TREE_INT_CST_HIGH (t)) != 0);
}
/* Add two doubleword integers with doubleword result.
--- 175,182 ----
/* Yield nonzero if signed overflow occurred. */
return
! ((overflow | (low ^ TREE_INT_CST_LOW (t)) | (high ^ TREE_INT_CST_HIGH (t)))
! != 0);
}
/* Add two doubleword integers with doubleword result.
***************
*** 1490,1495 ****
--- 1490,1497 ----
TREE_TYPE (t) = type;
TREE_CONSTANT_OVERFLOW (t) =
(TREE_CONSTANT_OVERFLOW (arg1)
+ | (TREE_INT_CST_HIGH (arg1) < 0
+ & TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (arg1)))
| force_fit_type (t, 0));
}
#if !defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC)
Technical Details
Message-ID:
<9211120639.AA26370@bi.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!constellation!convex!convex!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bi.TWinsun.COM!eggertShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!constellation!convex!convex!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bi.TWinsun.COM!eggert From: eggert@bi.TWinsun.COM (Paul Eggert) Subject: signed char c = 256; long long x = 9223372036854775808ULL; (GCC 2.3.1) Message-ID: <9211120639.AA26370@bi.twinsun.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Thu, 12 Nov 1992 06:39:36 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 77