Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Paul Eggert
Thu, 12 Nov 1992 06:39
signed char c = 256; long long x = 9223372036854775808ULL; (GCC 2.3.1)
Author: 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)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads