From patchwork Fri Mar 10 20:04:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 19513 Received: (qmail 79361 invoked by alias); 10 Mar 2017 20:04:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 79225 invoked by uid 89); 10 Mar 2017 20:04:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Mar 2017 20:04:48 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F239EC04B311 for ; Fri, 10 Mar 2017 20:04:48 +0000 (UTC) Received: from valrhona.uglyboxes.com (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2AK4lWw029240 for ; Fri, 10 Mar 2017 15:04:48 -0500 From: Keith Seitz To: gdb-patches@sourceware.org Subject: [PATCH v6 03/11] Add ability to return rvalue reference values from value_ref Date: Fri, 10 Mar 2017 12:04:38 -0800 Message-Id: <1489176286-27973-4-git-send-email-keiths@redhat.com> In-Reply-To: <1489176286-27973-1-git-send-email-keiths@redhat.com> References: <1489176286-27973-1-git-send-email-keiths@redhat.com> X-IsSubscribed: yes Parameterize value_ref() by the kind of reference type the value of which is requested. Change all callers to use the new API. There are no changes to this patch from v5. gdb/ChangeLog PR gdb/14441 From Artemiy Volkov * ada-lang.c (ada_evaluate_subexp): Adhere to the new value_ref() interface. * c-valprint.c (c_value_print): Likewise. * infcall.c (value_arg_coerce): Likewise. * python/py-value.c (valpy_reference_value): Likewise. * valops.c (value_cast, value_reinterpret_cast) (value_dynamic_cast, typecmp): Likewise. (value_ref): Parameterize by kind of return value reference type. * value.h (value_ref): Add new parameter "refcode". --- gdb/ChangeLog | 14 ++++++++++++++ gdb/ada-lang.c | 2 +- gdb/c-valprint.c | 10 +++++++--- gdb/infcall.c | 2 +- gdb/python/py-value.c | 2 +- gdb/python/py-xmethods.c | 5 +++-- gdb/valops.c | 25 +++++++++++++++++-------- gdb/value.h | 2 +- 8 files changed, 45 insertions(+), 17 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 0ec9777..4768848 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -2,6 +2,20 @@ PR gdb/14441 From Artemiy Volkov + * ada-lang.c (ada_evaluate_subexp): Adhere to the new + value_ref() interface. + * c-valprint.c (c_value_print): Likewise. + * infcall.c (value_arg_coerce): Likewise. + * python/py-value.c (valpy_reference_value): Likewise. + * valops.c (value_cast, value_reinterpret_cast) + (value_dynamic_cast, typecmp): Likewise. + (value_ref): Parameterize by kind of return value reference type. + * value.h (value_ref): Add new parameter "refcode". + +2017-MM-DD Keith Seitz + + PR gdb/14441 + From Artemiy Volkov * dwarf2read.c (read_tag_reference_type): Use lookup_lvalue_reference_type() instead of lookup_reference_type(). * eval.c (evaluate_subexp_standard): Likewise. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 753409c..9b91e0c 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10707,7 +10707,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, should return a ref as it should be valid to ask for its address; so rebuild a ref after coerce. */ arg1 = ada_coerce_ref (arg1); - return value_ref (arg1); + return value_ref (arg1, TYPE_CODE_REF); } } diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c index 5993195..d29b20e 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -606,10 +606,14 @@ c_value_print (struct value *val, struct ui_file *stream, else if (options->objectprint && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)) { - int is_ref = TYPE_CODE (type) == TYPE_CODE_REF; + int is_ref = TYPE_IS_REFERENCE (type); + enum type_code refcode = TYPE_CODE_UNDEF; if (is_ref) - val = value_addr (val); + { + val = value_addr (val); + refcode = TYPE_CODE (type); + } /* Pointer to class, check real type of object. */ fprintf_filtered (stream, "("); @@ -635,7 +639,7 @@ c_value_print (struct value *val, struct ui_file *stream, if (is_ref) { - val = value_ref (value_ind (val)); + val = value_ref (value_ind (val), refcode); type = value_type (val); } diff --git a/gdb/infcall.c b/gdb/infcall.c index f55acb5..713738e 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -168,7 +168,7 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, if the value was not previously in memory - in some cases we should clearly be allowing this, but how? */ new_value = value_cast (TYPE_TARGET_TYPE (type), arg); - new_value = value_ref (new_value); + new_value = value_ref (new_value, TYPE_CODE (type)); return new_value; } case TYPE_CODE_INT: diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 399978a..c0199ea 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -248,7 +248,7 @@ valpy_reference_value (PyObject *self, PyObject *args) scoped_value_mark free_values; self_val = ((value_object *) self)->value; - result = value_to_value_object (value_ref (self_val)); + result = value_to_value_object (value_ref (self_val, TYPE_CODE_REF)); } CATCH (except, RETURN_MASK_ALL) { diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index 8a9bb9b..d01488f 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -552,9 +552,10 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang, if (!types_equal (obj_type, this_ptr)) obj = value_cast (this_ptr, obj); } - else if (TYPE_CODE (obj_type) == TYPE_CODE_REF) + else if (TYPE_IS_REFERENCE (obj_type)) { - struct type *this_ref = lookup_lvalue_reference_type (this_type); + struct type *this_ref + = lookup_reference_type (this_type, TYPE_CODE (obj_type)); if (!types_equal (obj_type, this_ref)) obj = value_cast (this_ref, obj); diff --git a/gdb/valops.c b/gdb/valops.c index d218c92..21f4008 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -373,7 +373,7 @@ value_cast (struct type *type, struct value *arg2) struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1)); struct value *val = value_cast (dereftype, arg2); - return value_ref (val); + return value_ref (val, TYPE_CODE (t1)); } code2 = TYPE_CODE (check_typedef (value_type (arg2))); @@ -623,7 +623,8 @@ value_reinterpret_cast (struct type *type, struct value *arg) error (_("Invalid reinterpret_cast")); if (is_ref) - result = value_cast (type, value_ref (value_ind (result))); + result = value_cast (type, value_ref (value_ind (result), + TYPE_CODE (type))); return result; } @@ -819,7 +820,9 @@ value_dynamic_cast (struct type *type, struct value *arg) arg_type, &result) == 1) return value_cast (type, - is_ref ? value_ref (result) : value_addr (result)); + is_ref + ? value_ref (result, TYPE_CODE (resolved_type)) + : value_addr (result)); } /* The second dynamic check specified in 5.2.7. */ @@ -831,7 +834,9 @@ value_dynamic_cast (struct type *type, struct value *arg) value_address (tem), tem, rtti_type, &result) == 1) return value_cast (type, - is_ref ? value_ref (result) : value_addr (result)); + is_ref + ? value_ref (result, TYPE_CODE (resolved_type)) + : value_addr (result)); if (TYPE_CODE (resolved_type) == TYPE_CODE_PTR) return value_zero (type, not_lval); @@ -1527,16 +1532,20 @@ value_addr (struct value *arg1) contents. */ struct value * -value_ref (struct value *arg1) +value_ref (struct value *arg1, enum type_code refcode) { struct value *arg2; struct type *type = check_typedef (value_type (arg1)); - if (TYPE_CODE (type) == TYPE_CODE_REF) + gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF); + + if ((TYPE_CODE (type) == TYPE_CODE_REF + || TYPE_CODE (type) == TYPE_CODE_RVALUE_REF) + && TYPE_CODE (type) == refcode) return arg1; arg2 = value_addr (arg1); - deprecated_set_value_type (arg2, lookup_lvalue_reference_type (type)); + deprecated_set_value_type (arg2, lookup_reference_type (type, refcode)); return arg2; } @@ -1743,7 +1752,7 @@ typecmp (int staticp, int varargs, int nargs, if (TYPE_CODE (tt2) == TYPE_CODE_ARRAY) t2[i] = value_coerce_array (t2[i]); else - t2[i] = value_ref (t2[i]); + t2[i] = value_ref (t2[i], TYPE_CODE (tt1)); continue; } diff --git a/gdb/value.h b/gdb/value.h index c57ea79..a1d1609 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -775,7 +775,7 @@ extern struct value *value_ind (struct value *arg1); extern struct value *value_addr (struct value *arg1); -extern struct value *value_ref (struct value *arg1); +extern struct value *value_ref (struct value *arg1, enum type_code refcode); extern struct value *value_assign (struct value *toval, struct value *fromval);