* config.sub, config.guess: Update from upstream sources.
[deliverable/binutils-gdb.git] / gdb / valarith.c
index ef03fb9839cfc0afd3d3041f67abb1930238715e..2e5e97a0aeef2ef5d06a838abc399ddfd93180e5 100644 (file)
@@ -1,8 +1,8 @@
 /* Perform arithmetic and other operations on values, for GDB.
 
-   Copyright 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
-   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free
-   Software Foundation, Inc.
+   Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
+   1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
+   Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -18,8 +18,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301, USA.  */
 
 #include "defs.h"
 #include "value.h"
@@ -285,9 +285,9 @@ value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound
   return v;
 }
 \f
-/* Check to see if either argument is a structure.  This is called so
-   we know whether to go ahead with the normal binop or look for a 
-   user defined function instead.
+/* Check to see if either argument is a structure, or a reference to
+   one.  This is called so we know whether to go ahead with the normal
+   binop or look for a user defined function instead.
 
    For now, we do not overload the `=' operator.  */
 
@@ -297,14 +297,17 @@ binop_user_defined_p (enum exp_opcode op, struct value *arg1, struct value *arg2
   struct type *type1, *type2;
   if (op == BINOP_ASSIGN || op == BINOP_CONCAT)
     return 0;
+
   type1 = check_typedef (value_type (arg1));
+  if (TYPE_CODE (type1) == TYPE_CODE_REF)
+    type1 = check_typedef (TYPE_TARGET_TYPE (type1));
+
   type2 = check_typedef (value_type (arg2));
+  if (TYPE_CODE (type2) == TYPE_CODE_REF)
+    type2 = check_typedef (TYPE_TARGET_TYPE (type2));
+
   return (TYPE_CODE (type1) == TYPE_CODE_STRUCT
-         || TYPE_CODE (type2) == TYPE_CODE_STRUCT
-         || (TYPE_CODE (type1) == TYPE_CODE_REF
-             && TYPE_CODE (TYPE_TARGET_TYPE (type1)) == TYPE_CODE_STRUCT)
-         || (TYPE_CODE (type2) == TYPE_CODE_REF
-             && TYPE_CODE (TYPE_TARGET_TYPE (type2)) == TYPE_CODE_STRUCT));
+         || TYPE_CODE (type2) == TYPE_CODE_STRUCT);
 }
 
 /* Check to see if argument is a structure.  This is called so
@@ -883,7 +886,14 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
          Use the signedness of the operand with the greater length.
          If both operands are of equal length, use unsigned operation
          if one of the operands is unsigned.  */
-      if (promoted_len1 > promoted_len2)
+      if (op == BINOP_RSH || op == BINOP_LSH)
+       {
+         /* In case of the shift operators the type of the result only
+            depends on the type of the left operand.  */
+         unsigned_operation = is_unsigned1;
+         result_len = promoted_len1;
+       }
+      else if (promoted_len1 > promoted_len2)
        {
          unsigned_operation = is_unsigned1;
          result_len = promoted_len1;
@@ -1241,7 +1251,12 @@ value_equal (struct value *arg1, struct value *arg2)
                                                       BINOP_EQUAL)));
   else if ((code1 == TYPE_CODE_FLT || is_int1)
           && (code2 == TYPE_CODE_FLT || is_int2))
-    return value_as_double (arg1) == value_as_double (arg2);
+    {
+      /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
+        `long double' values are returned in static storage (m68k).  */
+      DOUBLEST d = value_as_double (arg1);
+      return d == value_as_double (arg2);
+    }
 
   /* FIXME: Need to promote to either CORE_ADDR or LONGEST, whichever
      is bigger.  */
@@ -1300,7 +1315,12 @@ value_less (struct value *arg1, struct value *arg2)
                                                       BINOP_LESS)));
   else if ((code1 == TYPE_CODE_FLT || is_int1)
           && (code2 == TYPE_CODE_FLT || is_int2))
-    return value_as_double (arg1) < value_as_double (arg2);
+    {
+      /* NOTE: kettenis/20050816: Avoid compiler bug on systems where
+        `long double' values are returned in static storage (m68k).  */
+      DOUBLEST d = value_as_double (arg1);
+      return d < value_as_double (arg2);
+    }
   else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
     return value_as_address (arg1) < value_as_address (arg2);
 
This page took 0.024696 seconds and 4 git commands to generate.