gdb/MAINTAINERS: add Luis Machado as global maintainer
[binutils-gdb.git] / gdb / eval.c
index 28b307f07c9e5fd1755ffdbb7b86d32fdfa75cf4..b859e825925b435e3ef79032055c7b0c7752ad2d 100644 (file)
@@ -25,7 +25,7 @@
 #include "target.h"
 #include "frame.h"
 #include "gdbthread.h"
-#include "language.h"          /* For CAST_IS_CONVERSION.  */
+#include "language.h"
 #include "cp-abi.h"
 #include "infcall.h"
 #include "objc-lang.h"
@@ -53,7 +53,7 @@ parse_and_eval_address (const char *exp)
 {
   expression_up expr = parse_expression (exp);
 
-  return value_as_address (evaluate_expression (expr.get ()));
+  return value_as_address (expr->evaluate ());
 }
 
 /* Like parse_and_eval_address, but treats the value of the expression
@@ -63,15 +63,15 @@ parse_and_eval_long (const char *exp)
 {
   expression_up expr = parse_expression (exp);
 
-  return value_as_long (evaluate_expression (expr.get ()));
+  return value_as_long (expr->evaluate ());
 }
 
 struct value *
-parse_and_eval (const char *exp)
+parse_and_eval (const char *exp, parser_flags flags)
 {
-  expression_up expr = parse_expression (exp);
+  expression_up expr = parse_expression (exp, nullptr, flags);
 
-  return evaluate_expression (expr.get ());
+  return expr->evaluate ();
 }
 
 /* Parse up to a comma (or to a closeparen)
@@ -81,9 +81,10 @@ parse_and_eval (const char *exp)
 struct value *
 parse_to_comma_and_eval (const char **expp)
 {
-  expression_up expr = parse_exp_1 (expp, 0, nullptr, 1);
+  expression_up expr = parse_exp_1 (expp, 0, nullptr,
+                                   PARSER_COMMA_TERMINATES);
 
-  return evaluate_expression (expr.get ());
+  return expr->evaluate ();
 }
 \f
 
@@ -111,28 +112,11 @@ expression::evaluate (struct type *expect_type, enum noside noside)
 
   if (stack_temporaries.has_value ()
       && value_in_thread_stack_temporaries (retval, inferior_thread ()))
-    retval = value_non_lval (retval);
+    retval = retval->non_lval ();
 
   return retval;
 }
 
-/* See value.h.  */
-
-struct value *
-evaluate_expression (struct expression *exp, struct type *expect_type)
-{
-  return exp->evaluate (expect_type, EVAL_NORMAL);
-}
-
-/* Evaluate an expression, avoiding all memory references
-   and getting a value whose type alone is correct.  */
-
-struct value *
-evaluate_type (struct expression *exp)
-{
-  return exp->evaluate (nullptr, EVAL_AVOID_SIDE_EFFECTS);
-}
-
 /* Find the current value of a watchpoint on EXP.  Return the value in
    *VALP and *RESULTP and the chain of intermediate and final values
    in *VAL_CHAIN.  RESULTP and VAL_CHAIN may be NULL if the caller does
@@ -212,7 +196,7 @@ fetch_subexp_value (struct expression *exp,
 
          try
            {
-             value_fetch_lazy (result);
+             result->fetch_lazy ();
              *valp = result;
            }
          catch (const gdb_exception_error &except)
@@ -371,29 +355,6 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
 
       switch (language->la_language)
        {
-       case language_c:
-       case language_cplus:
-       case language_asm:
-       case language_objc:
-         if (result_len <= builtin->builtin_int->length ())
-           {
-             promoted_type = (unsigned_operation
-                              ? builtin->builtin_unsigned_int
-                              : builtin->builtin_int);
-           }
-         else if (result_len <= builtin->builtin_long->length ())
-           {
-             promoted_type = (unsigned_operation
-                              ? builtin->builtin_unsigned_long
-                              : builtin->builtin_long);
-           }
-         else
-           {
-             promoted_type = (unsigned_operation
-                              ? builtin->builtin_unsigned_long_long
-                              : builtin->builtin_long_long);
-           }
-         break;
        case language_opencl:
          if (result_len
              <= lookup_signed_typename (language, "int")->length())
@@ -413,23 +374,29 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
            }
          break;
        default:
-         /* For other languages the result type is unchanged from gdb
-            version 6.7 for backward compatibility.
-            If either arg was long long, make sure that value is also long
-            long.  Otherwise use long.  */
-         if (unsigned_operation)
+         if (result_len <= builtin->builtin_int->length ())
            {
-             if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
-               promoted_type = builtin->builtin_unsigned_long_long;
-             else
-               promoted_type = builtin->builtin_unsigned_long;
+             promoted_type = (unsigned_operation
+                              ? builtin->builtin_unsigned_int
+                              : builtin->builtin_int);
+           }
+         else if (result_len <= builtin->builtin_long->length ())
+           {
+             promoted_type = (unsigned_operation
+                              ? builtin->builtin_unsigned_long
+                              : builtin->builtin_long);
+           }
+         else if (result_len <= builtin->builtin_long_long->length ())
+           {
+             promoted_type = (unsigned_operation
+                              ? builtin->builtin_unsigned_long_long
+                              : builtin->builtin_long_long);
            }
          else
            {
-             if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT)
-               promoted_type = builtin->builtin_long_long;
-             else
-               promoted_type = builtin->builtin_long;
+             promoted_type = (unsigned_operation
+                              ? builtin->builtin_uint128
+                              : builtin->builtin_int128);
            }
          break;
        }
@@ -552,7 +519,7 @@ type_instance_operation::evaluate (struct type *expect_type,
 value *
 evaluate_var_value (enum noside noside, const block *blk, symbol *var)
 {
-  /* JYG: We used to just return value_zero of the symbol type if
+  /* JYG: We used to just return value::zero of the symbol type if
      we're asked to avoid side effects.  Otherwise we return
      value_of_variable (...).  However I'm not sure if
      value_of_variable () has any side effect.  We need a full value
@@ -573,7 +540,7 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
       if (noside != EVAL_AVOID_SIDE_EFFECTS)
        throw;
 
-      ret = value_zero (var->type (), not_lval);
+      ret = value::zero (var->type (), not_lval);
     }
 
   return ret;
@@ -606,7 +573,7 @@ evaluate_var_msym_value (enum noside noside,
   type *the_type = find_minsym_type_and_address (msymbol, objfile, &address);
 
   if (noside == EVAL_AVOID_SIDE_EFFECTS && !the_type->is_gnu_ifunc ())
-    return value_zero (the_type, not_lval);
+    return value::zero (the_type, not_lval);
   else
     return value_at_lazy (the_type, address);
 }
@@ -635,16 +602,16 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
          /* We don't know anything about what the internal
             function might return, but we have to return
             something.  */
-         return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+         return value::zero (builtin_type (exp->gdbarch)->builtin_int,
                             not_lval);
        }
       else if (ftype->code () == TYPE_CODE_XMETHOD)
        {
-         type *return_type = result_type_of_xmethod (callee, argvec);
+         type *return_type = callee->result_type_of_xmethod (argvec);
 
          if (return_type == NULL)
            error (_("Xmethod is missing return type."));
-         return value_zero (return_type, not_lval);
+         return value::zero (return_type, not_lval);
        }
       else if (ftype->code () == TYPE_CODE_FUNC
               || ftype->code () == TYPE_CODE_METHOD)
@@ -666,7 +633,7 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
          if (return_type == NULL)
            error_call_unknown_return_type (function_name);
 
-         return allocate_value (return_type);
+         return value::allocate (return_type);
        }
       else
        error (_("Expression of type other than "
@@ -678,7 +645,7 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
       return call_internal_function (exp->gdbarch, exp->language_defn,
                                     callee, argvec.size (), argvec.data ());
     case TYPE_CODE_XMETHOD:
-      return call_xmethod (callee, argvec);
+      return callee->call_xmethod (argvec);
     default:
       return call_function_by_hand (callee, default_return_type, argvec);
     }
@@ -775,7 +742,7 @@ scope_operation::evaluate_funcall (struct type *expect_type,
       function_name = name.c_str ();
 
       /* We need a properly typed value for method lookup.  */
-      argvec[0] = value_zero (type, lval_memory);
+      argvec[0] = value::zero (type, lval_memory);
     }
 
   for (int i = 0; i < args.size (); ++i)
@@ -840,7 +807,7 @@ structop_member_base::evaluate_funcall (struct type *expect_type,
   if (a1_type->code () == TYPE_CODE_METHODPTR)
     {
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-       callee = value_zero (a1_type->target_type (), not_lval);
+       callee = value::zero (a1_type->target_type (), not_lval);
       else
        callee = cplus_method_ptr_to_value (&lhs, rhs);
 
@@ -1101,7 +1068,7 @@ eval_op_var_entry_value (struct type *expect_type, struct expression *exp,
                         enum noside noside, symbol *sym)
 {
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    return value_zero (sym->type (), not_lval);
+    return value::zero (sym->type (), not_lval);
 
   if (SYMBOL_COMPUTED_OPS (sym) == NULL
       || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
@@ -1165,7 +1132,7 @@ eval_op_register (struct type *expect_type, struct expression *exp,
      of the evaluation mode.  */
   if (noside == EVAL_AVOID_SIDE_EFFECTS
       && regno < gdbarch_num_cooked_regs (exp->gdbarch))
-    val = value_zero (register_type (exp->gdbarch, regno), not_lval);
+    val = value::zero (register_type (exp->gdbarch, regno), not_lval);
   else
     val = value_of_register (regno, get_selected_frame (NULL));
   if (val == NULL)
@@ -1188,6 +1155,23 @@ string_operation::evaluate (struct type *expect_type,
   return value_string (str.c_str (), str.size (), type);
 }
 
+struct value *
+ternop_slice_operation::evaluate (struct type *expect_type,
+                                 struct expression *exp,
+                                 enum noside noside)
+{
+  struct value *array
+    = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+  struct value *low
+    = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+  struct value *upper
+    = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
+
+  int lowbound = value_as_long (low);
+  int upperbound = value_as_long (upper);
+  return value_slice (array, lowbound, upperbound - lowbound + 1);
+}
+
 } /* namespace expr */
 
 /* Helper function that implements the body of OP_OBJC_SELECTOR.  */
@@ -1202,18 +1186,6 @@ eval_op_objc_selector (struct type *expect_type, struct expression *exp,
                             lookup_child_selector (exp->gdbarch, sel));
 }
 
-/* A helper function for TERNOP_SLICE.  */
-
-struct value *
-eval_op_ternop (struct type *expect_type, struct expression *exp,
-               enum noside noside,
-               struct value *array, struct value *low, struct value *upper)
-{
-  int lowbound = value_as_long (low);
-  int upperbound = value_as_long (upper);
-  return value_slice (array, lowbound, upperbound - lowbound + 1);
-}
-
 /* A helper function for STRUCTOP_STRUCT.  */
 
 struct value *
@@ -1224,7 +1196,7 @@ eval_op_structop_struct (struct type *expect_type, struct expression *exp,
   struct value *arg3 = value_struct_elt (&arg1, {}, string,
                                         NULL, "structure");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    arg3 = value_zero (arg3->type (), VALUE_LVAL (arg3));
+    arg3 = value::zero (arg3->type (), arg3->lval ());
   return arg3;
 }
 
@@ -1280,7 +1252,7 @@ eval_op_structop_ptr (struct type *expect_type, struct expression *exp,
   struct value *arg3 = value_struct_elt (&arg1, {}, string,
                                         NULL, "structure pointer");
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    arg3 = value_zero (arg3->type (), VALUE_LVAL (arg3));
+    arg3 = value::zero (arg3->type (), arg3->lval ());
   return arg3;
 }
 
@@ -1299,7 +1271,7 @@ eval_op_member (struct type *expect_type, struct expression *exp,
     {
     case TYPE_CODE_METHODPTR:
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-       return value_zero (type->target_type (), not_lval);
+       return value::zero (type->target_type (), not_lval);
       else
        {
          arg2 = cplus_method_ptr_to_value (&arg1, arg2);
@@ -1447,7 +1419,7 @@ eval_op_subscript (struct type *expect_type, struct expression *exp,
        }
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-       return value_zero (type->target_type (), VALUE_LVAL (arg1));
+       return value::zero (type->target_type (), arg1->lval ());
       else
        return value_subscript (arg1, value_as_long (arg2));
     }
@@ -1693,11 +1665,11 @@ eval_op_ind (struct type *expect_type, struct expression *exp,
          if (type->is_pointer_or_reference ()
              /* In C you can dereference an array to get the 1st elt.  */
              || type->code () == TYPE_CODE_ARRAY)
-           return value_zero (type->target_type (),
+           return value::zero (type->target_type (),
                               lval_memory);
          else if (type->code () == TYPE_CODE_INT)
            /* GDB allows dereferencing an int.  */
-           return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+           return value::zero (builtin_type (exp->gdbarch)->builtin_int,
                               lval_memory);
          else
            error (_("Attempt to take contents of a non-pointer value."));
@@ -1738,7 +1710,7 @@ eval_op_memval (struct type *expect_type, struct expression *exp,
                struct value *arg1, struct type *type)
 {
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    return value_zero (type, lval_memory);
+    return value::zero (type, lval_memory);
   else
     return value_at_lazy (type, value_as_address (arg1));
 }
@@ -1820,7 +1792,7 @@ eval_op_postinc (struct type *expect_type, struct expression *exp,
     }
   else
     {
-      struct value *arg3 = value_non_lval (arg1);
+      struct value *arg3 = arg1->non_lval ();
       struct value *arg2;
 
       if (ptrmath_type_p (exp->language_defn, arg1->type ()))
@@ -1854,7 +1826,7 @@ eval_op_postdec (struct type *expect_type, struct expression *exp,
     }
   else
     {
-      struct value *arg3 = value_non_lval (arg1);
+      struct value *arg3 = arg1->non_lval ();
       struct value *arg2;
 
       if (ptrmath_type_p (exp->language_defn, arg1->type ()))
@@ -1880,7 +1852,7 @@ eval_op_type (struct type *expect_type, struct expression *exp,
              enum noside noside, struct type *type)
 {
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    return allocate_value (type);
+    return value::allocate (type);
   else
     error (_("Attempt to use a type name as an expression"));
 }
@@ -2162,9 +2134,9 @@ eval_op_objc_msgcall (struct type *expect_type, struct expression *exp,
       if (callee_type)
        {
          if ((callee_type->code () == TYPE_CODE_ERROR) && expect_type)
-           return allocate_value (expect_type);
+           return value::allocate (expect_type);
          else
-           return allocate_value (callee_type);
+           return value::allocate (callee_type);
        }
       else
        error (_("Expression of type other than "
@@ -2383,7 +2355,7 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
       fieldno++;
       /* Skip static fields.  */
       while (fieldno < struct_type->num_fields ()
-            && field_is_static (&struct_type->field (fieldno)))
+            && struct_type->field (fieldno).is_static ())
        fieldno++;
       if (fieldno >= struct_type->num_fields ())
        error (_("too many initializers"));
@@ -2411,14 +2383,14 @@ array_operation::evaluate_struct_tuple (struct value *struct_val,
       if (val->type () != field_type)
        val = value_cast (field_type, val);
 
-      bitsize = TYPE_FIELD_BITSIZE (struct_type, fieldno);
+      bitsize = struct_type->field (fieldno).bitsize ();
       bitpos = struct_type->field (fieldno).loc_bitpos ();
-      addr = value_contents_writeable (struct_val).data () + bitpos / 8;
+      addr = struct_val->contents_writeable ().data () + bitpos / 8;
       if (bitsize)
        modify_field (struct_type, addr,
                      value_as_long (val), bitpos % 8, bitsize);
       else
-       memcpy (addr, value_contents (val).data (),
+       memcpy (addr, val->contents ().data (),
                val->type ()->length ());
 
     }
@@ -2430,19 +2402,17 @@ array_operation::evaluate (struct type *expect_type,
                           struct expression *exp,
                           enum noside noside)
 {
-  int tem;
-  int tem2 = std::get<0> (m_storage);
-  int tem3 = std::get<1> (m_storage);
+  const int provided_low_bound = std::get<0> (m_storage);
   const std::vector<operation_up> &in_args = std::get<2> (m_storage);
-  int nargs = tem3 - tem2 + 1;
+  const int nargs = std::get<1> (m_storage) - provided_low_bound + 1;
   struct type *type = expect_type ? check_typedef (expect_type) : nullptr;
 
   if (expect_type != nullptr
       && type->code () == TYPE_CODE_STRUCT)
     {
-      struct value *rec = allocate_value (expect_type);
+      struct value *rec = value::allocate (expect_type);
 
-      memset (value_contents_raw (rec).data (), '\0', type->length ());
+      memset (rec->contents_raw ().data (), '\0', type->length ());
       return evaluate_struct_tuple (rec, exp, noside, nargs);
     }
 
@@ -2451,33 +2421,28 @@ array_operation::evaluate (struct type *expect_type,
     {
       struct type *range_type = type->index_type ();
       struct type *element_type = type->target_type ();
-      struct value *array = allocate_value (expect_type);
+      struct value *array = value::allocate (expect_type);
       int element_size = check_typedef (element_type)->length ();
-      LONGEST low_bound, high_bound, index;
+      LONGEST low_bound, high_bound;
 
       if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
        {
          low_bound = 0;
          high_bound = (type->length () / element_size) - 1;
        }
-      index = low_bound;
-      memset (value_contents_raw (array).data (), 0, expect_type->length ());
-      for (tem = nargs; --nargs >= 0;)
+      if (low_bound + nargs - 1 > high_bound)
+       error (_("Too many array elements"));
+      memset (array->contents_raw ().data (), 0, expect_type->length ());
+      for (int idx = 0; idx < nargs; ++idx)
        {
          struct value *element;
 
-         element = in_args[index - low_bound]->evaluate (element_type,
-                                                         exp, noside);
+         element = in_args[idx]->evaluate (element_type, exp, noside);
          if (element->type () != element_type)
            element = value_cast (element_type, element);
-         if (index > high_bound)
-           /* To avoid memory corruption.  */
-           error (_("Too many array elements"));
-         memcpy (value_contents_raw (array).data ()
-                 + (index - low_bound) * element_size,
-                 value_contents (element).data (),
+         memcpy (array->contents_raw ().data () + idx * element_size,
+                 element->contents ().data (),
                  element_size);
-         index++;
        }
       return array;
     }
@@ -2485,8 +2450,8 @@ array_operation::evaluate (struct type *expect_type,
   if (expect_type != nullptr
       && type->code () == TYPE_CODE_SET)
     {
-      struct value *set = allocate_value (expect_type);
-      gdb_byte *valaddr = value_contents_raw (set).data ();
+      struct value *set = value::allocate (expect_type);
+      gdb_byte *valaddr = set->contents_raw ().data ();
       struct type *element_type = type->index_type ();
       struct type *check_type = element_type;
       LONGEST low_bound, high_bound;
@@ -2499,14 +2464,13 @@ array_operation::evaluate (struct type *expect_type,
       if (!get_discrete_bounds (element_type, &low_bound, &high_bound))
        error (_("(power)set type with unknown size"));
       memset (valaddr, '\0', type->length ());
-      int idx = 0;
-      for (tem = 0; tem < nargs; tem++)
+      for (int idx = 0; idx < nargs; idx++)
        {
          LONGEST range_low, range_high;
          struct type *range_low_type, *range_high_type;
          struct value *elem_val;
 
-         elem_val = in_args[idx++]->evaluate (element_type, exp, noside);
+         elem_val = in_args[idx]->evaluate (element_type, exp, noside);
          range_low_type = range_high_type = elem_val->type ();
          range_low = range_high = value_as_long (elem_val);
 
@@ -2548,14 +2512,14 @@ array_operation::evaluate (struct type *expect_type,
       return set;
     }
 
-  value **argvec = XALLOCAVEC (struct value *, nargs);
-  for (tem = 0; tem < nargs; tem++)
+  std::vector<value *> argvec (nargs);
+  for (int tem = 0; tem < nargs; tem++)
     {
       /* Ensure that array expressions are coerced into pointer
         objects.  */
       argvec[tem] = in_args[tem]->evaluate_with_coercion (exp, noside);
     }
-  return value_array (tem2, tem3, argvec);
+  return value_array (provided_low_bound, argvec);
 }
 
 value *
@@ -2569,8 +2533,8 @@ unop_extract_operation::evaluate (struct type *expect_type,
   if (type->length () > old_value->type ()->length ())
     error (_("length type is larger than the value type"));
 
-  struct value *result = allocate_value (type);
-  value_contents_copy (result, 0, old_value, 0, type->length ());
+  struct value *result = value::allocate (type);
+  old_value->contents_copy (result, 0, 0, type->length ());
   return result;
 }
 
@@ -2588,10 +2552,10 @@ evaluate_subexp_for_address_base (struct expression *exp, enum noside noside,
       struct type *type = check_typedef (x->type ());
 
       if (TYPE_IS_REFERENCE (type))
-       return value_zero (lookup_pointer_type (type->target_type ()),
+       return value::zero (lookup_pointer_type (type->target_type ()),
                           not_lval);
-      else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
-       return value_zero (lookup_pointer_type (x->type ()),
+      else if (x->lval () == lval_memory || value_must_coerce_to_target (x))
+       return value::zero (lookup_pointer_type (x->type ()),
                           not_lval);
       else
        error (_("Attempt to take address of "
@@ -2656,7 +2620,7 @@ var_msym_value_operation::evaluate_for_address (struct expression *exp,
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     {
       struct type *type = lookup_pointer_type (val->type ());
-      return value_zero (type, not_lval);
+      return value::zero (type, not_lval);
     }
   else
     return value_addr (val);
@@ -2702,7 +2666,7 @@ var_value_operation::evaluate_for_address (struct expression *exp,
          || sym_class == LOC_REGISTER)
        error (_("Attempt to take address of register or constant."));
 
-      return value_zero (type, not_lval);
+      return value::zero (type, not_lval);
     }
   else
     return address_of_variable (var, std::get<0> (m_storage).block);
@@ -2852,10 +2816,10 @@ var_value_operation::evaluate_for_sizeof (struct expression *exp,
          /* FIXME: This should be size_t.  */
          struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
          if (type_not_allocated (type) || type_not_associated (type))
-           return value_zero (size_type, not_lval);
+           return value::zero (size_type, not_lval);
          else if (is_dynamic_type (type->index_type ())
                   && type->bounds ()->high.kind () == PROP_UNDEFINED)
-           return allocate_optimized_out_value (size_type);
+           return value::allocate_optimized_out (size_type);
        }
     }
   return evaluate_subexp_for_sizeof_base (exp, type);
@@ -2867,7 +2831,7 @@ var_msym_value_operation::evaluate_for_cast (struct type *to_type,
                                             enum noside noside)
 {
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
-    return value_zero (to_type, not_lval);
+    return value::zero (to_type, not_lval);
 
   const bound_minimal_symbol &b = std::get<0> (m_storage);
   value *val = evaluate_var_msym_value (noside, b.objfile, b.minsym);
@@ -2875,11 +2839,11 @@ var_msym_value_operation::evaluate_for_cast (struct type *to_type,
   val = value_cast (to_type, val);
 
   /* Don't allow e.g. '&(int)var_with_no_debug_info'.  */
-  if (VALUE_LVAL (val) == lval_memory)
+  if (val->lval () == lval_memory)
     {
       if (val->lazy ())
-       value_fetch_lazy (val);
-      VALUE_LVAL (val) = not_lval;
+       val->fetch_lazy ();
+      val->set_lval (not_lval);
     }
   return val;
 }
@@ -2896,11 +2860,11 @@ var_value_operation::evaluate_for_cast (struct type *to_type,
   val = value_cast (to_type, val);
 
   /* Don't allow e.g. '&(int)var_with_no_debug_info'.  */
-  if (VALUE_LVAL (val) == lval_memory)
+  if (val->lval () == lval_memory)
     {
       if (val->lazy ())
-       value_fetch_lazy (val);
-      VALUE_LVAL (val) = not_lval;
+       val->fetch_lazy ();
+      val->set_lval (not_lval);
     }
   return val;
 }