* gdbarch.sh (software_single_step): Replace REGCACHE argument by
[deliverable/binutils-gdb.git] / gdb / valarith.c
index 2e1471c3bc464a983f4db2f59f321393c962b7d7..31705bde21a2d6593e4388acb91db611deb6142c 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, 2007
+   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
@@ -805,8 +808,8 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
       /* If either arg was long double, make sure that value is also long
          double.  */
 
-      if (TYPE_LENGTH (type1) * 8 > TARGET_DOUBLE_BIT
-         || TYPE_LENGTH (type2) * 8 > TARGET_DOUBLE_BIT)
+      if (TYPE_LENGTH (type1) * 8 > gdbarch_double_bit (current_gdbarch)
+         || TYPE_LENGTH (type2) * 8 > gdbarch_double_bit (current_gdbarch))
        val = allocate_value (builtin_type_long_double);
       else
        val = allocate_value (builtin_type_double);
@@ -1025,7 +1028,7 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
          /* Can't just call init_type because we wouldn't know what
             name to give the type.  */
          val = allocate_value
-           (result_len > TARGET_LONG_BIT / HOST_CHAR_BIT
+           (result_len > gdbarch_long_bit (current_gdbarch) / HOST_CHAR_BIT
             ? builtin_type_unsigned_long_long
             : builtin_type_unsigned_long);
          store_unsigned_integer (value_contents_raw (val),
@@ -1150,7 +1153,7 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
          /* Can't just call init_type because we wouldn't know what
             name to give the type.  */
          val = allocate_value
-           (result_len > TARGET_LONG_BIT / HOST_CHAR_BIT
+           (result_len > gdbarch_long_bit (current_gdbarch) / HOST_CHAR_BIT
             ? builtin_type_long_long
             : builtin_type_long);
          store_signed_integer (value_contents_raw (val),
@@ -1248,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.  */
@@ -1307,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.025583 seconds and 4 git commands to generate.