This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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: RFC: fix PR c++/9197


>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:

Jan> You could leave EVAL_AVOID_SIDE_EFFECTS there in a comment so that
Jan> when "lval_type" gets implemented as part of the
Jan> archer-jankratochvil-vla rework it is not forgotten during
Jan> EVAL_AVOID_SIDE_EFFECTS grepping one could use "lval_type" there.

Ok, I'll do that.

Jan> Bugzilla is now down so I just reiterate that for example this gets fixed:

Jan> class C { virtual void m() {} } c;
Jan> int main() {}
Jan> (gdb) ptype c.m
Jan> Type C has no component named m.
Jan> -> 
Jan> type = void (C * const)

I think this may need additional work, related to the overloading bug I
filed recently.

Jan> I was trying to find where the value_struct_elt solution would not
Jan> work while "lval_type" would but in fact I have not found any.  So
Jan> as the only disadvantage remains only the needless negligibly sized
Jan> inferior memory read.

I've appended what I was hacking on.

According to my notes it causes some regressions in its current state.
Also, it is incomplete, since there are still many cases that read
memory even with EVAL_AVOID_SIDE_EFFECTS.  And finally, there are all
kinds of lurking weirdness.  For example, this patch trips over the call
to value_logical_not in value_cast_pointers.  There are plenty more
things like this to solve.

Tom

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 75f1c3d..95a6972 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -9310,6 +9310,9 @@ ada_value_cast (struct type *type, struct value *arg2, enum noside noside)
   if (type == ada_check_typedef (value_type (arg2)))
     return arg2;
 
+  if (noside == EVAL_AVOID_SIDE_EFFECTS)
+    return allocate_type_value (type);
+
   if (ada_is_fixed_point_type (type))
     return (cast_to_fixed (type, arg2));
 
@@ -9725,7 +9728,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
         {
           binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
-          return value_zero (value_type (arg1), not_lval);
+          return allocate_type_value (value_type (arg1));
         }
       else
         {
@@ -9850,7 +9853,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 		     This can happen if the debugging information is
 		     incomplete, for instance.  */
 		  actual_type = type;
-		return value_zero (actual_type, not_lval);
+		return allocate_type_value (actual_type);
 	      }
 	    else
 	      {
@@ -9864,10 +9867,9 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
           }
 
           *pos += 4;
-          return value_zero
+          return allocate_type_value
             (to_static_fixed_type
-             (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))),
-             not_lval);
+             (static_unwrap_type (SYMBOL_TYPE (exp->elts[pc + 2].symbol))));
         }
       else
         {
@@ -9949,8 +9951,8 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	      struct type *rtype = TYPE_TARGET_TYPE (type);
 
 	      if (TYPE_GNU_IFUNC (type))
-		return allocate_value (TYPE_TARGET_TYPE (rtype));
-	      return allocate_value (rtype);
+		return allocate_type_value (TYPE_TARGET_TYPE (rtype));
+	      return allocate_type_value (rtype);
 	    }
           return call_function_by_hand (argvec[0], nargs, argvec + 1);
 	case TYPE_CODE_INTERNAL_FUNCTION:
@@ -9958,8 +9960,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	    /* 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,
-			       not_lval);
+	    return allocate_type_value (builtin_type (exp->gdbarch)->builtin_int);
 	  else
 	    return call_internal_function (exp->gdbarch, exp->language_defn,
 					   argvec[0], nargs, argvec + 1);
@@ -9975,7 +9976,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
             if (arity != nargs)
               error (_("wrong number of subscripts; expecting %d"), arity);
             if (noside == EVAL_AVOID_SIDE_EFFECTS)
-              return value_zero (ada_aligned_type (type), lval_memory);
+              return allocate_type_value (ada_aligned_type (type));
             return
               unwrap_value (ada_value_subscript
                             (argvec[0], nargs, argvec + 1));
@@ -9987,7 +9988,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
               if (type == NULL)
                 error (_("element type of array unknown"));
               else
-                return value_zero (ada_aligned_type (type), lval_memory);
+                return allocate_type_value (ada_aligned_type (type));
             }
           return
             unwrap_value (ada_value_subscript
@@ -10001,7 +10002,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
               if (type == NULL)
                 error (_("element type of array unknown"));
               else
-                return value_zero (ada_aligned_type (type), lval_memory);
+                return allocate_type_value (ada_aligned_type (type));
             }
           return
             unwrap_value (ada_value_ptr_subscript (argvec[0], type,
@@ -10135,7 +10136,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	{
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
-	  return value_zero (type, not_lval);
+	  return allocate_type_value (type);
 	}
 
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -10214,7 +10215,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	      type = builtin_type (exp->gdbarch)->builtin_int;
 
             if (noside == EVAL_AVOID_SIDE_EFFECTS)
-              return allocate_value (type);
+              return allocate_type_value (type);
 
             switch (op)
               {
@@ -10269,7 +10270,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	      type = builtin_type (exp->gdbarch)->builtin_int;
 
             if (noside == EVAL_AVOID_SIDE_EFFECTS)
-              return allocate_value (type);
+              return allocate_type_value (type);
 
             switch (op)
               {
@@ -10295,7 +10296,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         goto nosideret;
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return value_zero (ada_tag_type (arg1), not_lval);
+        return allocate_type_value (ada_tag_type (arg1));
 
       return ada_value_tag (arg1);
 
@@ -10307,7 +10308,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return value_zero (value_type (arg1), not_lval);
+        return allocate_type_value (value_type (arg1));
       else
 	{
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
@@ -10338,7 +10339,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         goto nosideret;
       type = builtin_type (exp->gdbarch)->builtin_int;
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (type, not_lval);
+	return allocate_type_value (type);
       else
 	return value_pos_atr (type, arg1);
 
@@ -10355,7 +10356,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return value_zero (builtin_type (exp->gdbarch)->builtin_int, not_lval);
+        return allocate_type_value (builtin_type (exp->gdbarch)->builtin_int);
       else
         return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
                                    TARGET_CHAR_BIT * TYPE_LENGTH (type));
@@ -10367,7 +10368,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return value_zero (type, not_lval);
+        return allocate_type_value (type);
       else
         return value_val_atr (type, arg1);
 
@@ -10377,7 +10378,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return value_zero (value_type (arg1), not_lval);
+        return allocate_type_value (value_type (arg1));
       else
 	{
 	  /* For integer exponentiation operations,
@@ -10421,7 +10422,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 
               if (arrType == NULL)
                 error (_("Attempt to dereference null array pointer."));
-              return value_at_lazy (arrType, 0);
+              return allocate_type_value (arrType);
             }
           else if (TYPE_CODE (type) == TYPE_CODE_PTR
                    || TYPE_CODE (type) == TYPE_CODE_REF
@@ -10432,19 +10433,18 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                 (ada_aligned_type
                  (ada_check_typedef (TYPE_TARGET_TYPE (type))));
               check_size (type);
-              return value_zero (type, lval_memory);
+              return allocate_type_value (type);
             }
           else if (TYPE_CODE (type) == TYPE_CODE_INT)
 	    {
 	      /* GDB allows dereferencing an int.  */
 	      if (expect_type == NULL)
-		return value_zero (builtin_type (exp->gdbarch)->builtin_int,
-				   lval_memory);
+		return allocate_type_value (builtin_type (exp->gdbarch)->builtin_int);
 	      else
 		{
 		  expect_type = 
 		    to_static_fixed_type (ada_aligned_type (expect_type));
-		  return value_zero (expect_type, lval_memory);
+		  return allocate_type_value (expect_type);
 		}
 	    }
           else
@@ -10492,15 +10492,14 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                    in some extension of the type.  Return an object of 
                    "type" void, which will match any formal 
                    (see ada_type_match).  */
-                return value_zero (builtin_type (exp->gdbarch)->builtin_void,
-				   lval_memory);
+                return allocate_type_value (builtin_type (exp->gdbarch)->builtin_void);
             }
           else
             type =
               ada_lookup_struct_elt_type (type1, &exp->elts[pc + 2].string, 1,
                                           0, NULL);
 
-          return value_zero (ada_aligned_type (type), lval_memory);
+          return allocate_type_value (ada_aligned_type (type));
         }
       else
         arg1 = ada_value_struct_elt (arg1, &exp->elts[pc + 2].string, 0);
@@ -10514,7 +10513,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
       if (noside == EVAL_SKIP)
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        return allocate_value (exp->elts[pc + 1].type);
+        return allocate_type_value (exp->elts[pc + 1].type);
       else
         error (_("Attempt to use a type name as an expression"));
 
diff --git a/gdb/defs.h b/gdb/defs.h
index d8a1adb..389522f 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -394,7 +394,11 @@ enum lval_type
     lval_internalvar_component,
     /* Value's bits are fetched and stored using functions provided by
        its creator.  */
-    lval_computed
+    lval_computed,
+    /* The value is used to just carry a type.  Operations on the
+       value's type, like indirection, yield a new lval_type value.
+       Other operations are invalid.  */
+    lval_type
   };
 
 /* Control types for commands */
diff --git a/gdb/eval.c b/gdb/eval.c
index d7f80e2..2e423e0 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -749,15 +749,6 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
 	goto nosideret;
 
-      /* 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 object returned here for whatis_exp ()
-	 to call evaluate_type () and then pass the full value to
-	 value_rtti_target_type () if we are dealing with a pointer
-	 or reference to a base class and print object is on.  */
-
       {
 	volatile struct gdb_exception except;
 	struct value *ret = NULL;
@@ -771,8 +762,8 @@ evaluate_subexp_standard (struct type *expect_type,
 	if (except.reason < 0)
 	  {
 	    if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	      ret = value_zero (SYMBOL_TYPE (exp->elts[pc + 2].symbol),
-				not_lval);
+	      ret
+		= allocate_type_value (SYMBOL_TYPE (exp->elts[pc + 2].symbol));
 	    else
 	      throw_exception (except);
 	  }
@@ -790,7 +781,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	struct frame_info *frame;
 
 	if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	  return value_zero (SYMBOL_TYPE (sym), not_lval);
+	  return allocate_type_value (SYMBOL_TYPE (sym));
 
 	if (SYMBOL_CLASS (sym) != LOC_COMPUTED
 	    || SYMBOL_COMPUTED_OPS (sym)->read_variable_at_entry == NULL)
@@ -826,7 +817,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	if (noside == EVAL_AVOID_SIDE_EFFECTS
 	    && regno < gdbarch_num_regs (exp->gdbarch)
 			+ gdbarch_num_pseudo_regs (exp->gdbarch))
-	  val = value_zero (register_type (exp->gdbarch, regno), not_lval);
+	  val = allocate_type_value (register_type (exp->gdbarch, regno));
 	else
 	  val = value_of_register (regno, get_selected_frame (NULL));
 	if (val == NULL)
@@ -1391,7 +1382,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	  if (TYPE_CODE (type) == TYPE_CODE_METHODPTR)
 	    {
 	      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-		arg1 = value_zero (TYPE_TARGET_TYPE (type), not_lval);
+		arg1 = allocate_type_value (TYPE_TARGET_TYPE (type));
 	      else
 		arg1 = cplus_method_ptr_to_value (&arg2, arg1);
 
@@ -1743,8 +1734,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	      /* 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,
-				 not_lval);
+	      return allocate_type_value (builtin_type (exp->gdbarch)->builtin_int);
 	    }
 	  else if (TYPE_GNU_IFUNC (ftype))
 	    return allocate_value (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (ftype)));
@@ -1847,18 +1837,9 @@ evaluate_subexp_standard (struct type *expect_type,
       arg1 = evaluate_subexp (NULL_TYPE, exp, pos, noside);
       if (noside == EVAL_SKIP)
 	goto nosideret;
-      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (lookup_struct_elt_type (value_type (arg1),
-						   &exp->elts[pc + 2].string,
-						   0),
-			   lval_memory);
-      else
-	{
-	  struct value *temp = arg1;
 
-	  return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
-				   NULL, "structure");
-	}
+      return value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
+			       NULL, "structure");
 
     case STRUCTOP_PTR:
       tem = longest_to_int (exp->elts[pc + 1].longconst);
@@ -1908,18 +1889,8 @@ evaluate_subexp_standard (struct type *expect_type,
           }
       }
 
-      if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (lookup_struct_elt_type (value_type (arg1),
-						   &exp->elts[pc + 2].string,
-						   0),
-			   lval_memory);
-      else
-	{
-	  struct value *temp = arg1;
-
-	  return value_struct_elt (&temp, NULL, &exp->elts[pc + 2].string,
-				   NULL, "structure pointer");
-	}
+      return value_struct_elt (&arg1, NULL, &exp->elts[pc + 2].string,
+			       NULL, "structure pointer");
 
     case STRUCTOP_MEMBER:
     case STRUCTOP_MPTR:
@@ -1938,7 +1909,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	{
 	case TYPE_CODE_METHODPTR:
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	    return value_zero (TYPE_TARGET_TYPE (type), not_lval);
+	    return allocate_type_value (TYPE_TARGET_TYPE (type));
 	  else
 	    {
 	      arg2 = cplus_method_ptr_to_value (&arg1, arg2);
@@ -1947,10 +1918,18 @@ evaluate_subexp_standard (struct type *expect_type,
 	    }
 
 	case TYPE_CODE_MEMBERPTR:
+
 	  /* Now, convert these values to an address.  */
 	  arg1 = value_cast_pointers (lookup_pointer_type (TYPE_DOMAIN_TYPE (type)),
 				      arg1, 1);
 
+	  /* Note that in this case we want to call
+	     value_cast_pointers first, to ensure an error if we try
+	     to apply the pointer-to-member to an object of the wrong
+	     type.  */
+	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
+	    return allocate_type_value (TYPE_TARGET_TYPE (type));
+
 	  mem_offset = value_as_long (arg2);
 
 	  arg3 = value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
@@ -2158,7 +2137,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	    }
 
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	    return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
+	    return allocate_type_value (TYPE_TARGET_TYPE (type));
 	  else
 	    return value_subscript (arg1, value_as_long (arg2));
 	}
@@ -2200,7 +2179,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	      type = TYPE_TARGET_TYPE (check_typedef (value_type (arg1)));
 	      if (type != NULL)
 		{
-		  arg1 = value_zero (type, VALUE_LVAL (arg1));
+		  arg1 = allocate_type_value (type);
 		  noside = EVAL_SKIP;
 		  continue;
 		}
@@ -2530,12 +2509,10 @@ evaluate_subexp_standard (struct type *expect_type,
 	  /* In C you can dereference an array to get the 1st elt.  */
 	      || TYPE_CODE (type) == TYPE_CODE_ARRAY
 	    )
-	    return value_zero (TYPE_TARGET_TYPE (type),
-			       lval_memory);
+	    return allocate_type_value (TYPE_TARGET_TYPE (type));
 	  else if (TYPE_CODE (type) == TYPE_CODE_INT)
 	    /* GDB allows dereferencing an int.  */
-	    return value_zero (builtin_type (exp->gdbarch)->builtin_int,
-			       lval_memory);
+	    return allocate_type_value (builtin_type (exp->gdbarch)->builtin_int);
 	  else
 	    error (_("Attempt to take contents of a non-pointer value."));
 	}
@@ -2617,7 +2594,7 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
 	goto nosideret;
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (exp->elts[pc + 1].type, lval_memory);
+	return allocate_type_value (exp->elts[pc + 1].type);
       else
 	return value_at_lazy (exp->elts[pc + 1].type,
 			      value_as_address (arg1));
@@ -2629,7 +2606,7 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
 	goto nosideret;
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (type, lval_memory);
+	return allocate_type_value (type);
       else
 	return value_at_lazy (type, value_as_address (arg1));
 
@@ -2639,7 +2616,7 @@ evaluate_subexp_standard (struct type *expect_type,
       if (noside == EVAL_SKIP)
 	goto nosideret;
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (exp->elts[pc + 2].type, lval_memory);
+	return allocate_type_value (exp->elts[pc + 2].type);
       else
 	{
 	  CORE_ADDR tls_addr;
@@ -2905,8 +2882,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
 	      || sym_class == LOC_REGISTER)
 	    error (_("Attempt to take address of register or constant."));
 
-	  return
-	    value_zero (type, not_lval);
+	  return allocate_type_value (type);
 	}
       else
 	return address_of_variable (var, exp->elts[pc + 1].block);
@@ -2930,11 +2906,9 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
 	  struct type *type = check_typedef (value_type (x));
 
 	  if (TYPE_CODE (type) == TYPE_CODE_REF)
-	    return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
-			       not_lval);
+	    return allocate_type_value (lookup_pointer_type (TYPE_TARGET_TYPE (type)));
 	  else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
-	    return value_zero (lookup_pointer_type (value_type (x)),
-			       not_lval);
+	    return allocate_type_value (lookup_pointer_type (value_type (x)));
 	  else
 	    error (_("Attempt to take address of "
 		     "value not located in memory."));
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 48b5b3c..cfd0c6c 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -963,7 +963,7 @@ evaluate_subexp_java (struct type *expect_type, struct expression *exp,
 	    el_type = lookup_pointer_type (el_type);
 
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	    return value_zero (el_type, VALUE_LVAL (arg1));
+	    return allocate_type_value (el_type);
 	  address = value_as_address (arg1);
 	  address += get_java_object_header_size (exp->gdbarch);
 	  read_memory (address, buf4, 4);
@@ -978,7 +978,7 @@ evaluate_subexp_java (struct type *expect_type, struct expression *exp,
       else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
 	{
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	    return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
+	    return allocate_type_value (TYPE_TARGET_TYPE (type));
 	  else
 	    return value_subscript (arg1, value_as_long (arg2));
 	}
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 31e9a56..a9bc23e 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -257,7 +257,7 @@ evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp,
 	  }
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
+	return allocate_type_value (TYPE_TARGET_TYPE (type));
       else
 	return value_subscript (arg1, value_as_long (arg2));
 
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 819a832..bf94706 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -384,7 +384,7 @@ create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
   if (n == 1)
     {
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-        ret = value_zero (elm_type, not_lval);
+        ret = allocate_type_value (elm_type);
       else
         ret = value_subscript (val, indices[0]);
     }
@@ -403,7 +403,7 @@ create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside,
       make_cv_type (TYPE_CONST (type), TYPE_VOLATILE (type), dst_type, NULL);
 
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	ret = allocate_value (dst_type);
+	ret = allocate_type_value (dst_type);
       else
 	{
 	  /* Check whether to create a lvalue or not.  */
@@ -1035,15 +1035,9 @@ Cannot perform conditional operation on vectors with different sizes"));
 	  }
 	else
 	  {
-	    if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	      return
-		  value_zero (lookup_struct_elt_type
-			      (value_type (arg1),&exp->elts[pc + 2].string, 0),
-			      lval_memory);
-	    else
-	      return value_struct_elt (&arg1, NULL,
-				       &exp->elts[pc + 2].string, NULL,
-				       "structure");
+	    return value_struct_elt (&arg1, NULL,
+				     &exp->elts[pc + 2].string, NULL,
+				     "structure");
 	  }
       }
     default:
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 18c14fc..191f9ad 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -487,7 +487,7 @@ value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op,
 
 	  return_type
 	    = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
-	  return value_zero (return_type, VALUE_LVAL (arg1));
+	  return allocate_type_value (return_type);
 	}
       return call_function_by_hand (argvec[0], 2 - static_memfuncp,
 				    argvec + 1);
@@ -591,7 +591,7 @@ value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
 
 	  return_type
 	    = TYPE_TARGET_TYPE (check_typedef (value_type (argvec[0])));
-	  return value_zero (return_type, VALUE_LVAL (arg1));
+	  return allocate_type_value (return_type);
 	}
       return call_function_by_hand (argvec[0], nargs, argvec + 1);
     }
diff --git a/gdb/valops.c b/gdb/valops.c
index 93c09d8..eb6ef96 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -317,7 +317,8 @@ value_cast_pointers (struct type *type, struct value *arg2,
 
   if (TYPE_CODE (t1) == TYPE_CODE_STRUCT
       && TYPE_CODE (t2) == TYPE_CODE_STRUCT
-      && (subclass_check || !value_logical_not (arg2)))
+      && (subclass_check || (VALUE_LVAL (arg2) != lval_type
+			     && !value_logical_not (arg2))))
     {
       struct value *v2;
 
@@ -331,9 +332,15 @@ value_cast_pointers (struct type *type, struct value *arg2,
       /* At this point we have what we can have, un-dereference if needed.  */
       if (v2)
 	{
-	  struct value *v = value_addr (v2);
+	  struct value *v;
 
-	  deprecated_set_value_type (v, type);
+	  if (VALUE_LVAL (v2) == lval_type)
+	    v = allocate_type_value (type);
+	  else
+	    {
+	      v = value_addr (v2);
+	      deprecated_set_value_type (v, type);
+	    }
 	  return v;
 	}
    }
@@ -1636,17 +1643,21 @@ struct value *
 value_coerce_array (struct value *arg1)
 {
   struct type *type = check_typedef (value_type (arg1));
+  struct type *ptr_type;
 
   /* If the user tries to do something requiring a pointer with an
      array that has not yet been pushed to the target, then this would
      be a good time to do so.  */
   arg1 = value_coerce_to_target (arg1);
 
-  if (VALUE_LVAL (arg1) != lval_memory)
+  if (VALUE_LVAL (arg1) != lval_memory
+      && VALUE_LVAL (arg1) != lval_type)
     error (_("Attempt to take address of value not located in memory."));
 
-  return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
-			     value_address (arg1));
+  ptr_type = lookup_pointer_type (TYPE_TARGET_TYPE (type));
+  if (VALUE_LVAL (arg1) == lval_type)
+    return allocate_type_value (ptr_type);
+  return value_from_pointer (ptr_type, value_address (arg1));
 }
 
 /* Given a value which is a function, return a value which is a pointer
@@ -1655,14 +1666,16 @@ value_coerce_array (struct value *arg1)
 struct value *
 value_coerce_function (struct value *arg1)
 {
-  struct value *retval;
+  struct type *ptr_type;
 
-  if (VALUE_LVAL (arg1) != lval_memory)
+  if (VALUE_LVAL (arg1) != lval_memory
+      && VALUE_LVAL (arg1) != lval_type)
     error (_("Attempt to take address of value not located in memory."));
 
-  retval = value_from_pointer (lookup_pointer_type (value_type (arg1)),
-			       value_address (arg1));
-  return retval;
+  ptr_type = lookup_pointer_type (value_type (arg1));
+  if (VALUE_LVAL (arg1) == lval_type)
+    return allocate_type_value (ptr_type);
+  return value_from_pointer (ptr_type, value_address (arg1));
 }
 
 /* Return a pointer value for the object for which ARG1 is the
@@ -1756,6 +1769,9 @@ value_ind (struct value *arg1)
     {
       struct type *enc_type;
 
+      if (VALUE_LVAL (arg1) == lval_type)
+	return allocate_type_value (TYPE_TARGET_TYPE (base_type));
+
       /* We may be pointing to something embedded in a larger object.
          Get the real type of the enclosing object.  */
       enc_type = check_typedef (value_enclosing_type (arg1));
@@ -3303,7 +3319,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 	      (lookup_memberptr_type (TYPE_FIELD_TYPE (t, i), domain),
 	       offset + (LONGEST) (TYPE_FIELD_BITPOS (t, i) >> 3));
 	  else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-	    return allocate_value (TYPE_FIELD_TYPE (t, i));
+	    return allocate_type_value (TYPE_FIELD_TYPE (t, i));
 	  else
 	    error (_("Cannot reference non-static field \"%s\""), name);
 	}
@@ -3413,7 +3429,7 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 					 TYPE_FN_FIELD_VOFFSET (f, j), 1);
 		}
 	      else if (noside == EVAL_AVOID_SIDE_EFFECTS)
-		return allocate_value (TYPE_FN_FIELD_TYPE (f, j));
+		return allocate_type_value (TYPE_FN_FIELD_TYPE (f, j));
 	      else
 		error (_("Cannot reference virtual member function \"%s\""),
 		       name);
@@ -3517,7 +3533,7 @@ value_maybe_namespace_elt (const struct type *curtype,
     return NULL;
   else if ((noside == EVAL_AVOID_SIDE_EFFECTS)
 	   && (SYMBOL_CLASS (sym) == LOC_TYPEDEF))
-    result = allocate_value (SYMBOL_TYPE (sym));
+    result = allocate_type_value (SYMBOL_TYPE (sym));
   else
     result = value_of_variable (sym, get_selected_block (0));
 
diff --git a/gdb/value.c b/gdb/value.c
index 4b70ece..11fce22 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -691,6 +691,9 @@ allocate_value_lazy (struct type *type)
 void
 allocate_value_contents (struct value *val)
 {
+  /* You cannot get the contents of an lval_type value.  */
+  gdb_assert (VALUE_LVAL (val) != lval_type);
+
   if (!val->contents)
     val->contents = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type));
 }
@@ -748,6 +751,17 @@ allocate_optimized_out_value (struct type *type)
   return retval;
 }
 
+/* Allocate 'lval_type' value for TYPE.  */
+
+struct value *
+allocate_type_value (struct type *type)
+{
+  struct value *v = allocate_value_lazy (type);
+
+  VALUE_LVAL (v) = lval_type;
+  return v;
+}
+
 /* Accessor methods.  */
 
 struct value *
diff --git a/gdb/value.h b/gdb/value.h
index c10c3ec..0e03362 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -243,6 +243,10 @@ extern int valprint_check_validity (struct ui_file *stream, struct type *type,
 
 extern struct value *allocate_optimized_out_value (struct type *type);
 
+/* Allocate 'lval_type' value for TYPE.  */
+
+extern struct value *allocate_type_value (struct type *type);
+
 /* If VALUE is lval_computed, return its lval_funcs structure.  */
 
 extern const struct lval_funcs *value_computed_funcs (const struct value *);


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