tree.c (int_fits_type_p): A narrower type always fits in a wider one...
authorRoger Sayle <roger@eyesopen.com>
Sat, 1 Jan 2005 20:33:28 +0000 (20:33 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Sat, 1 Jan 2005 20:33:28 +0000 (20:33 +0000)
* tree.c (int_fits_type_p): A narrower type always fits in a
wider one, except for negative values into unsigned types.

Co-Authored-By: Olivier Hainque <hainque@act-europe.fr>
From-SVN: r92788

gcc/ChangeLog
gcc/tree.c

index 159941cec258c82ccf1374360376cfccbb4823f9..503f153413412dd7e584874580d04c8c25d070dd 100644 (file)
@@ -1,3 +1,9 @@
+2005-01-01  Roger Sayle  <roger@eyesopen.com>
+           Olivier Hainque  <hainque@act-europe.fr>
+
+       * tree.c (int_fits_type_p): A narrower type always fits in a
+       wider one, except for negative values into unsigned types.
+
 2005-01-01  Roger Sayle  <roger@eyesopen.com>
 
        * tree.c (int_fits_type_p): Compare the result of force_fit_type
index ca97e30351e4b89d8bdc9d388bc6e5086b7f23d5..e648aaa6b45d5745eac294b228151ebe3a0a6e5a 100644 (file)
@@ -4879,10 +4879,17 @@ int_fits_type_p (tree c, tree type)
   /* Perform some generic filtering first, which may allow making a decision
      even if the bounds are not constant.  First, negative integers never fit
      in unsigned types, */
-  if ((TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
-      /* Also, unsigned integers with top bit set never fit signed types.  */
-      || (! TYPE_UNSIGNED (type)
-         && TYPE_UNSIGNED (TREE_TYPE (c)) && tree_int_cst_msb (c)))
+  if (TYPE_UNSIGNED (type) && tree_int_cst_sgn (c) < 0)
+    return 0;
+
+  /* Second, narrower types always fit in wider ones.  */
+  if (TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (c)))
+    return 1;
+
+  /* Third, unsigned integers with top bit set never fit signed types.  */
+  if (! TYPE_UNSIGNED (type)
+      && TYPE_UNSIGNED (TREE_TYPE (c))
+      && tree_int_cst_msb (c))
     return 0;
 
   /* If at least one bound of the type is a constant integer, we can check