From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25764 invoked by alias); 6 Jun 2016 19:23:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 25542 invoked by uid 89); 6 Jun 2016 19:23:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=adhere, sk:type_is, sk:TYPE_IS X-HELO: mail-lf0-f66.google.com Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 06 Jun 2016 19:22:51 +0000 Received: by mail-lf0-f66.google.com with SMTP id k192so5861315lfb.1 for ; Mon, 06 Jun 2016 12:22:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=lER7xLZOM/qArGSsqJClgWuSEmcGFcYrL67Ijy8v9TY=; b=FkzgwSwNa2r+8p3mrBGD7vdtw5Plh23y7r7ucNBLfQWD5aXWcRHLcw/cvtjUUVEsCa NyfJ6CjA/8pN/7kl/CWdubn79WhpvDe5gMtPXM2JmjucqIfGeDb+3eHnGdMNGZUVMUdx +ZLsbPJRW9+Npi2B9yBoDkyYBU2sWngL8Amj+BiQVd21tUSqw3FxXwqiyMuCMe8tzUgj G0W8rSwmGAY4IzpxCsfW5ddrWf3d6nqQhX+2HMrtsc1QDUhYVjJqF9PZ2ztNUuWyk++F P0iG3y7vqZtH7xASzd3Eh/hoRCNV0mbjhsvazaQwXoiKMzgwMQN9JNoq1ViiOklhDLXC 5BWQ== X-Gm-Message-State: ALyK8tJ18lmQrrPCQc+hPWmURU9tyShSq7O3uxKyX5gdqnoAl5fKHDhUoU0C4e5jChTxBA== X-Received: by 10.25.19.211 with SMTP id 80mr172293lft.147.1465240967964; Mon, 06 Jun 2016 12:22:47 -0700 (PDT) Received: from localhost.localdomain (broadband-90-154-70-138.nationalcablenetworks.ru. [90.154.70.138]) by smtp.gmail.com with ESMTPSA id jv7sm1970253lbc.4.2016.06.06.12.22.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 12:22:46 -0700 (PDT) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: palves@redhat.com, keiths@redhat.com, Artemiy Volkov Subject: [PATCH v5 03/11] [PR gdb/14441] gdb: valops: add ability to return rvalue reference values from value_ref() Date: Mon, 06 Jun 2016 19:23:00 -0000 Message-Id: <20160606192225.12384-4-artemiyv@acm.org> In-Reply-To: <20160606192225.12384-1-artemiyv@acm.org> References: <1458593958-25656-1-git-send-email-artemiyv@acm.org> <20160606192225.12384-1-artemiyv@acm.org> X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00113.txt.bz2 Parameterize value_ref() by the kind of reference type the value of which is requested. Change all callers to use the new API. gdb/ChangeLog: 2016-06-06 Artemiy Volkov PR gdb/14441 * 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/ada-lang.c | 2 +- gdb/c-valprint.c | 8 ++++++-- gdb/infcall.c | 2 +- gdb/python/py-value.c | 2 +- gdb/valops.c | 25 +++++++++++++++++-------- gdb/value.h | 2 +- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 412aa97..96b905b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10738,7 +10738,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 61302a3..637acf0 100644 --- a/gdb/c-valprint.c +++ b/gdb/c-valprint.c @@ -604,10 +604,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, "("); diff --git a/gdb/infcall.c b/gdb/infcall.c index 77cd931..ad2512a 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -169,7 +169,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 e1eb7bb..73cc6bd 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -249,7 +249,7 @@ valpy_reference_value (PyObject *self, PyObject *args) struct cleanup *cleanup = make_cleanup_value_free_to_mark (value_mark ()); 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)); do_cleanups (cleanup); } diff --git a/gdb/valops.c b/gdb/valops.c index 8252f06..c2fc0db 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -372,7 +372,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))); @@ -622,7 +622,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; } @@ -816,7 +817,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. */ @@ -828,7 +831,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); @@ -1517,16 +1522,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; } @@ -1733,7 +1742,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 f8ec854..ed4d3d0 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -725,7 +725,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); -- 2.8.3