fold-const.c (make_range): Only narrow to signed range if the signed range is smaller...
authorHartmut Penner <hpenner@de.ibm.com>
Thu, 12 Sep 2002 06:49:26 +0000 (06:49 +0000)
committerRichard Henderson <rth@gcc.gnu.org>
Thu, 12 Sep 2002 06:49:26 +0000 (23:49 -0700)
        * fold-const.c (make_range): Only narrow to signed range if
        the signed range is smaller than the unsigned range.

* gcc.c-torture/execute/20020911-1.c: New.

From-SVN: r57050

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

index 701bd4c78457601c42a1ea07bffe428268663aac..914ae17b2fb4c332a7eb72cdb602cc329685d342 100644 (file)
@@ -1,3 +1,8 @@
+2002-09-11  Hartmut Penner  <hpenner@de.ibm.com>
+
+       * fold-const.c (make_range): Only narrow to signed range if
+       the signed range is smaller than the unsigned range.
+
 2002-09-12  Alan Modra  <amodra@bigpond.net.au>
 
        * emit-rtl.c (set_mem_size): New function.
index b8da1a74b2693ab75abd2dac8a77a0054e78cc05..1b2124a737e7cd23a5e2f5f97d8b7ed51f6311b3 100644 (file)
@@ -3089,9 +3089,10 @@ make_range (exp, pin_p, plow, phigh)
                = TYPE_MAX_VALUE (equiv_type) ? TYPE_MAX_VALUE (equiv_type)
                  : TYPE_MAX_VALUE (type);
 
-             high_positive = fold (build (RSHIFT_EXPR, type,
-                                          convert (type, high_positive),
-                                          convert (type, integer_one_node)));
+             if (TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (exp)))
+               high_positive = fold (build (RSHIFT_EXPR, type,
+                                            convert (type, high_positive),
+                                            convert (type, integer_one_node)));
 
              /* If the low bound is specified, "and" the range with the
                 range for which the original unsigned value will be
diff --git a/gcc/testsuite/gcc.c-torture/execute/20020911-1.c b/gcc/testsuite/gcc.c-torture/execute/20020911-1.c
new file mode 100644 (file)
index 0000000..ec83022
--- /dev/null
@@ -0,0 +1,8 @@
+extern void abort (void);
+unsigned short c = 0x8000;
+int main()
+{
+  if ((c-0x8000) < 0 || (c-0x8000) > 0x7fff)
+    abort();
+  return 0;
+}