re PR middle-end/23522 (fold_widened_comparison bug)
authorAlexey Starovoytov <alexey.starovoytov@sun.com>
Tue, 18 Oct 2005 03:16:21 +0000 (03:16 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 18 Oct 2005 03:16:21 +0000 (03:16 +0000)
PR middle-end/23522
* fold-const.c (fold_widened_comparison): Do not allow range based
constant folding when right operand cannot be unwidened.

Co-Authored-By: Ian Lance Taylor <ian@airs.com>
From-SVN: r105536

gcc/ChangeLog
gcc/fold-const.c

index 91973cd7465ff1dcd732d80537a9df67172b1b44..439ea318c23d26cae5db8dd40e37c1096bb7ef30 100644 (file)
@@ -1,3 +1,10 @@
+2005-10-17  Alexey Starovoytov  <alexey.starovoytov@sun.com>
+            Ian Lance Taylor <ian@airs.com>
+
+       PR middle-end/23522
+       * fold-const.c (fold_widened_comparison): Do not allow range based
+       constant folding when right operand cannot be unwidened.
+
 2005-10-17  Richard Henderson  <rth@redhat.com>
 
        * builtins.c (expand_builtin_synchronize): Build a new-style asm
index 015930e5ca67c71ade40fd436e9f903c1797b78c..a6aa1df818c4785f6eadfb36f54b90985b3eb2ee 100644 (file)
@@ -6250,8 +6250,6 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
     return NULL_TREE;
 
   arg1_unw = get_unwidened (arg1, shorter_type);
-  if (!arg1_unw)
-    return NULL_TREE;
 
   /* If possible, express the comparison in the shorter mode.  */
   if ((code == EQ_EXPR || code == NE_EXPR
@@ -6264,7 +6262,9 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
     return fold_build2 (code, type, arg0_unw,
                       fold_convert (shorter_type, arg1_unw));
 
-  if (TREE_CODE (arg1_unw) != INTEGER_CST)
+  if (TREE_CODE (arg1_unw) != INTEGER_CST
+      || TREE_CODE (shorter_type) != INTEGER_TYPE
+      || !int_fits_type_p (arg1_unw, shorter_type))
     return NULL_TREE;
 
   /* If we are comparing with the integer that does not fit into the range