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: [PATCH v3 09/11] [PR gdb/14441] gdb: convert lvalue reference type check to general reference type check


On 03/04/2016 07:19 PM, Artemiy Volkov wrote:
> In almost all contexts (except for overload resolution rules and expression
> semantics), lvalue and rvalue references are equivalent. That means that in all
> but these cases we can replace a TYPE_CODE_REF check to a TYPE_IS_REFERENCE
> check and, for switch statements, add a case label for a rvalue reference type
> next to a case label for an lvalue reference type. This patch does exactly
> that.

> diff --git a/gdb/valops.c b/gdb/valops.c
> index 1f423a0..30e1c59 100644
> --- a/gdb/valops.c
> +++ b/gdb/valops.c
> @@ -317,7 +317,7 @@ value_cast_pointers (struct type *type, struct value *arg2,
>      {
>        struct value *v2;
>  
> -      if (TYPE_CODE (type2) == TYPE_CODE_REF)
> +      if (TYPE_IS_REFERENCE (type2))
>  	v2 = coerce_ref (arg2);
>        else
>  	v2 = value_ind (arg2);
> @@ -363,21 +363,21 @@ value_cast (struct type *type, struct value *arg2)
>    code1 = TYPE_CODE (check_typedef (type));
>  

code1 isn't used anymore in this early part of the function. It is later
unconditionally assigned a new value, so I would just remove this
assignment.

>    /* Check if we are casting struct reference to struct reference.  */
> -  if (code1 == TYPE_CODE_REF)
> +  if (TYPE_IS_REFERENCE (check_typedef (type)))
>      {
>        /* We dereference type; then we recurse and finally
>           we generate value of the given reference.  Nothing wrong with 
>  	 that.  */
>        struct type *t1 = check_typedef (type);
>        struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1));
> -      struct value *val =  value_cast (dereftype, arg2);
> +      struct value *val = value_cast (dereftype, arg2);
>  
>        return value_ref (val, TYPE_CODE (t1));
>      }
>  
>    code2 = TYPE_CODE (check_typedef (value_type (arg2)));

And I believe the same with code2. It isn't used until later, and by
that time, it has been assigned a new value.
>  
> -  if (code2 == TYPE_CODE_REF)
> +  if (TYPE_IS_REFERENCE (check_typedef (value_type (arg2))))
>      /* We deref the value and then do the cast.  */
>      return value_cast (type, coerce_ref (arg2)); 
>  

Keith


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