]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.c (build_range_check): Use proper type for subtraction when merging lower...
authorRichard Kenner <kenner@vlsi1.ultra.nyu.edu>
Fri, 18 Nov 2005 13:07:06 +0000 (13:07 +0000)
committerRichard Kenner <kenner@gcc.gnu.org>
Fri, 18 Nov 2005 13:07:06 +0000 (08:07 -0500)
* fold-const.c (build_range_check): Use proper type for subtraction
when merging lower bound.

From-SVN: r107178

gcc/ChangeLog
gcc/fold-const.c

index 9a0a77cb00efa821d3b5ed7e8802cef401a7a896..ad2c25a44c958c7b156fa8a597354312ca0a129d 100644 (file)
@@ -1,3 +1,8 @@
+2005-11-18  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>
+
+       * fold-const.c (build_range_check): Use proper type for subtraction
+       when merging lower bound.
+
 2005-11-18  Zdenek Dvorak  <dvorakz@suse.cz>
 
        PR rtl-optimization/24497
index 343cfae690370056729c2e9d4b66f7a53d98a511..abaac755e3b30704d6391cbfa317ccb9676dd08f 100644 (file)
@@ -4062,10 +4062,22 @@ build_range_check (tree type, tree exp, int in_p, tree low, tree high)
     }
 
   if (value != 0 && ! TREE_OVERFLOW (value))
-    return build_range_check (type,
-                             fold_build2 (MINUS_EXPR, etype, exp, low),
-                             1, fold_convert (etype, integer_zero_node),
-                             value);
+    {
+      /* There is no requirement that LOW be within the range of ETYPE
+        if the latter is a subtype.  It must, however, be within the base
+        type of ETYPE.  So be sure we do the subtraction in that type.  */
+      if (INTEGRAL_TYPE_P (etype) && TREE_TYPE (etype))
+       {
+         etype = TREE_TYPE (etype);
+         exp = fold_convert (etype, exp);
+         low = fold_convert (etype, low);
+         value = fold_convert (etype, value);
+       }
+
+      return build_range_check (type,
+                               fold_build2 (MINUS_EXPR, etype, exp, low),
+                               1, build_int_cst (etype, 0), value);
+    }
 
   return 0;
 }