[gdb/testsuite] Add PR number in KFAIL in gdb.ada/array_ptr_renaming.exp
[deliverable/binutils-gdb.git] / gdb / eval.c
index 87874420dc8643f422b78a7adac9039c89198a9a..3b1f4943b43e9f07535cace9b3836bde91caf0c3 100644 (file)
@@ -1,6 +1,6 @@
 /* Evaluate expressions for GDB.
 
-   Copyright (C) 1986-2019 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -562,20 +562,20 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
          break;
        case language_opencl:
          if (result_len <= TYPE_LENGTH (lookup_signed_typename
-                                        (language, gdbarch, "int")))
+                                        (language, "int")))
            {
              promoted_type =
                (unsigned_operation
-                ? lookup_unsigned_typename (language, gdbarch, "int")
-                : lookup_signed_typename (language, gdbarch, "int"));
+                ? lookup_unsigned_typename (language, "int")
+                : lookup_signed_typename (language, "int"));
            }
          else if (result_len <= TYPE_LENGTH (lookup_signed_typename
-                                             (language, gdbarch, "long")))
+                                             (language, "long")))
            {
              promoted_type =
                (unsigned_operation
-                ? lookup_unsigned_typename (language, gdbarch, "long")
-                : lookup_signed_typename (language, gdbarch,"long"));
+                ? lookup_unsigned_typename (language, "long")
+                : lookup_signed_typename (language,"long"));
            }
          break;
        default:
@@ -1248,6 +1248,20 @@ skip_undetermined_arglist (int nargs, struct expression *exp, int *pos,
     evaluate_subexp (NULL_TYPE, exp, pos, noside);
 }
 
+/* Return true if type is integral or reference to integral */
+
+static bool
+is_integral_or_integral_reference (struct type *type)
+{
+  if (is_integral_type (type))
+    return true;
+
+  type = check_typedef (type);
+  return (type != nullptr
+         && TYPE_IS_REFERENCE (type)
+         && is_integral_type (TYPE_TARGET_TYPE (type)));
+}
+
 struct value *
 evaluate_subexp_standard (struct type *expect_type,
                          struct expression *exp, int *pos,
@@ -2208,10 +2222,10 @@ evaluate_subexp_standard (struct type *expect_type,
       if (binop_user_defined_p (op, arg1, arg2))
        return value_x_binop (arg1, arg2, op, OP_NULL, noside);
       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
-              && is_integral_type (value_type (arg2)))
+              && is_integral_or_integral_reference (value_type (arg2)))
        return value_ptradd (arg1, value_as_long (arg2));
       else if (ptrmath_type_p (exp->language_defn, value_type (arg2))
-              && is_integral_type (value_type (arg1)))
+              && is_integral_or_integral_reference (value_type (arg1)))
        return value_ptradd (arg2, value_as_long (arg1));
       else
        {
@@ -2234,7 +2248,7 @@ evaluate_subexp_standard (struct type *expect_type,
          return value_from_longest (type, value_ptrdiff (arg1, arg2));
        }
       else if (ptrmath_type_p (exp->language_defn, value_type (arg1))
-              && is_integral_type (value_type (arg2)))
+              && is_integral_or_integral_reference (value_type (arg2)))
        return value_ptradd (arg1, - value_as_long (arg2));
       else
        {
This page took 0.027062 seconds and 4 git commands to generate.