aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2010-01-14 10:47:09 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2010-01-14 10:47:09 +0100
commit5f8d50239ba11866a5e0251975142fee6632ab2f (patch)
treef281e4baaa435f4349cbed1f76a9f1ae97fba37a /gcc
parent429c98c9a813a425c325f992126c365898f56d94 (diff)
downloadgcc-5f8d50239ba11866a5e0251975142fee6632ab2f.zip
gcc-5f8d50239ba11866a5e0251975142fee6632ab2f.tar.gz
gcc-5f8d50239ba11866a5e0251975142fee6632ab2f.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/fold-const.c8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr42721.c21
4 files changed, 41 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 88f7830..8f4c326 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 9e40296..9d249cc 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index faac669..0478ae5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr42721.c b/gcc/testsuite/gcc.c-torture/execute/pr42721.c
new file mode 100644
index 0000000..706921b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr42721.c
@@ -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;
+}