PR c/42721
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jan 2010 09:47:09 +0000 (09:47 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 14 Jan 2010 09:47:09 +0000 (09:47 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@155887 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr42721.c [new file with mode: 0644]

index 88f7830..8f4c326 100644 (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
index 9e40296..9d249cc 100644 (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);
 }
index faac669..0478ae5 100644 (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
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr42721.c b/gcc/testsuite/gcc.c-torture/execute/pr42721.c
new file mode 100644 (file)
index 0000000..706921b
--- /dev/null
@@ -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;
+}