re PR c/42721 (possible integer wrong code bug)

PR c/42721
	Port from no-undefined-overflow branch
	2009-03-09  Richard Guenther  <rguenther@suse.de>

	* fold-const.c (add_double_with_sign): Fix unsigned overflow
	detection.

	* gcc.c-torture/execute/pr42721.c: New test.

From-SVN: r155887
This commit is contained in:
Jakub Jelinek 2010-01-14 10:47:09 +01:00 committed by Jakub Jelinek
parent 429c98c9a8
commit 5f8d50239b
4 changed files with 41 additions and 2 deletions

View File

@ -1,3 +1,12 @@
2010-01-14 Jakub Jelinek <jakub@redhat.com>
PR c/42721
Port from no-undefined-overflow branch
2009-03-09 Richard Guenther <rguenther@suse.de>
* fold-const.c (add_double_with_sign): Fix unsigned overflow
detection.
2010-01-14 Richard Guenther <rguenther@suse.de>
PR lto/42665

View File

@ -326,13 +326,17 @@ add_double_with_sign (unsigned HOST_WIDE_INT l1, HOST_WIDE_INT h1,
HOST_WIDE_INT h;
l = l1 + l2;
h = h1 + h2 + (l < l1);
h = (HOST_WIDE_INT) ((unsigned HOST_WIDE_INT) h1
+ (unsigned HOST_WIDE_INT) h2
+ (l < l1));
*lv = l;
*hv = h;
if (unsigned_p)
return (unsigned HOST_WIDE_INT) h < (unsigned HOST_WIDE_INT) h1;
return ((unsigned HOST_WIDE_INT) h < (unsigned HOST_WIDE_INT) h1
|| (h == h1
&& l < l1));
else
return OVERFLOW_SUM_SIGN (h1, h2, h);
}

View File

@ -1,3 +1,8 @@
2010-01-14 Jakub Jelinek <jakub@redhat.com>
PR c/42721
* gcc.c-torture/execute/pr42721.c: New test.
2010-01-14 Ira Rosen <irar@il.ibm.com>
PR tree-optimization/42709

View File

@ -0,0 +1,21 @@
/* PR c/42721 */
extern void abort (void);
static unsigned long long
foo (unsigned long long x, unsigned long long y)
{
return x / y;
}
static int a, b;
int
main (void)
{
unsigned long long c = 1;
b ^= c && (foo (a, -1ULL) != 1L);
if (b != 1)
abort ();
return 0;
}