]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/32628 (bogus integer overflow warning)
authorRichard Guenther <rguenther@suse.de>
Wed, 16 Jan 2008 21:51:57 +0000 (21:51 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 16 Jan 2008 21:51:57 +0000 (21:51 +0000)
2008-01-16  Richard Guenther  <rguenther@suse.de>

PR middle-end/32628
* fold-const.c (fold_convert_const_int_from_int): Do not
set overflow if that occured only because of a sign extension
change when converting from/to a sizetype with the same
precision and signedness.

* gcc.dg/overflow-warn-7.c: New testcase.

From-SVN: r131579

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/overflow-warn-7.c [new file with mode: 0644]

index 9dc1e213afd73365a66932eb9fd83f2a7fe10b6e..0aa13b5c526f22f80aa9f27c0b9a144a4c126ad4 100644 (file)
@@ -1,3 +1,11 @@
+2008-01-16  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/32628
+       * fold-const.c (fold_convert_const_int_from_int): Do not
+       set overflow if that occured only because of a sign extension
+       change when converting from/to a sizetype with the same
+       precision and signedness.
+
 2008-01-16  Uros Bizjak  <ubizjak@gmail.com>
 
        PR debug/34249
index 22350b98bf4189d747c6e42f7c40fe3231fd2656..ea0b43e942d27ea455cd52e017a45a7b593db034 100644 (file)
@@ -2122,8 +2122,22 @@ fold_convert_const_int_from_int (tree type, const_tree arg1)
   t = force_fit_type_double (type, TREE_INT_CST_LOW (arg1),
                             TREE_INT_CST_HIGH (arg1),
                             /* Don't set the overflow when
-                               converting a pointer  */
-                            !POINTER_TYPE_P (TREE_TYPE (arg1)),
+                               converting from a pointer,  */
+                            !POINTER_TYPE_P (TREE_TYPE (arg1))
+                            /* or to a sizetype with same signedness
+                               and the precision is unchanged.
+                               ???  sizetype is always sign-extended,
+                               but its signedness depends on the
+                               frontend.  Thus we see spurious overflows
+                               here if we do not check this.  */
+                            && !((TYPE_PRECISION (TREE_TYPE (arg1))
+                                  == TYPE_PRECISION (type))
+                                 && (TYPE_UNSIGNED (TREE_TYPE (arg1))
+                                     == TYPE_UNSIGNED (type))
+                                 && ((TREE_CODE (TREE_TYPE (arg1)) == INTEGER_TYPE
+                                      && TYPE_IS_SIZETYPE (TREE_TYPE (arg1)))
+                                     || (TREE_CODE (type) == INTEGER_TYPE
+                                         && TYPE_IS_SIZETYPE (type)))),
                             (TREE_INT_CST_HIGH (arg1) < 0
                              && (TYPE_UNSIGNED (type)
                                  < TYPE_UNSIGNED (TREE_TYPE (arg1))))
index 591ca646e928e3703721371f1cb0cfe840d1aa47..155e98eb1c737cb967eac8bcd0c618efc846310c 100644 (file)
@@ -1,3 +1,8 @@
+2008-01-16  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/32628
+       * gcc.dg/overflow-warn-7.c: New testcase.
+
 2008-01-16  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * gcc.dg/tree-ssa/loop-19.c: Require nonpic.
diff --git a/gcc/testsuite/gcc.dg/overflow-warn-7.c b/gcc/testsuite/gcc.dg/overflow-warn-7.c
new file mode 100644 (file)
index 0000000..7c0ce68
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int f(char *device)
+{
+  return device == ((char *)0 + ~0UL);  /* { dg-bogus "overflow" } */
+}
+