This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v3 09/11] [PR gdb/14441] gdb: convert lvalue reference type check to general reference type check
- From: Keith Seitz <keiths at redhat dot com>
- To: Artemiy Volkov <artemiyv at acm dot org>, "gdb-patches at sourceware dot org ml" <gdb-patches at sourceware dot org>
- Date: Wed, 16 Mar 2016 15:41:51 -0700
- Subject: Re: [PATCH v3 09/11] [PR gdb/14441] gdb: convert lvalue reference type check to general reference type check
- Authentication-results: sourceware.org; auth=none
- References: <1453229609-20159-1-git-send-email-artemiyv at acm dot org> <1457147955-21871-1-git-send-email-artemiyv at acm dot org> <1457147955-21871-10-git-send-email-artemiyv at acm dot org>
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