This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: underlying type of C++ enums [changes ABI, ok for 3.1?]


On Apr 25, 2002, Jason Merrill <jason@redhat.com> wrote:

>>>>>> "Alexandre" == Alexandre Oliva <aoliva@redhat.com> writes:
>> On Apr 25, 2002, Jason Merrill <jason@redhat.com> wrote:
>>> I would think it would make more sense to fix tree_int_cst_lt.

>> I thought it made sense for it to make such the assumption that both
>> constants had the same types.

> Why?  What harm would it do for it to be more robust?

I was only thinking of performance.  But I think this patch wouldn't
cause as much of a performance drop as I had thought this would
require at first.  Bootstrapped and tested on athlon-pc-linux-gnu.  Ok
to install?

Index: gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* tree.c (tree_int_cst_lt): Compare constants whose types differ
	in unsigned-ness correctly.

Index: gcc/tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.c,v
retrieving revision 1.252
diff -u -p -r1.252 tree.c
--- gcc/tree.c 24 Apr 2002 20:40:45 -0000 1.252
+++ gcc/tree.c 26 Apr 2002 02:19:57 -0000
@@ -3230,7 +3230,20 @@ tree_int_cst_lt (t1, t2)
   if (t1 == t2)
     return 0;
 
-  if (! TREE_UNSIGNED (TREE_TYPE (t1)))
+  if (TREE_UNSIGNED (TREE_TYPE (t1)) != TREE_UNSIGNED (TREE_TYPE (t2)))
+    {
+      int t1_sgn = tree_int_cst_sgn (t1);
+      int t2_sgn = tree_int_cst_sgn (t2);
+
+      if (t1_sgn < t2_sgn)
+	return 1;
+      else if (t1_sgn > t2_sgn)
+	return 0;
+      /* Otherwise, both are non-negative, so we compare them as
+	 unsigned just in case one of them would overflow a signed
+	 type.  */
+    }
+  else if (! TREE_UNSIGNED (TREE_TYPE (t1)))
     return INT_CST_LT (t1, t2);
 
   return INT_CST_LT_UNSIGNED (t1, t2);

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]