From patchwork Wed Feb 27 20:00:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 31637 Received: (qmail 69430 invoked by alias); 27 Feb 2019 20:01:05 -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 69094 invoked by uid 89); 27 Feb 2019 20:00:44 -0000 Authentication-Results: sourceware.org; auth=none 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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=parms X-HELO: mail.efficios.com Received: from mail.efficios.com (HELO mail.efficios.com) (167.114.142.138) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 27 Feb 2019 20:00:40 +0000 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 2D13F807D3 for ; Wed, 27 Feb 2019 15:00:38 -0500 (EST) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id Nj294V7469FF; Wed, 27 Feb 2019 15:00:37 -0500 (EST) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id D30C3807B3; Wed, 27 Feb 2019 15:00:37 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com D30C3807B3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1551297637; bh=/xhjKSt9oQT+/z8GcyVmpaPE3j4tAFCRVon2Px9iQes=; h=From:To:Date:Message-Id:MIME-Version; b=VTTKgwVIiDrcRrwtiKAizVL6iytaL/PbfjEmeNOREodcV/YLX/G3CRolqNKhBEJ3p 7CujYOYdlQW/cbD+MW/fv0ReVtJQk5A1YNdTJXCzPl8G7fg902I9s69knInxpYiM4s ApbI4WuBNpUyyWOA9xQU7gokcZ7cHg0zrirSIZVAKh6w/v9FFt96D2WR6hmZ2ctxRT w7BxF0sC9to2esHN2LMxMtmjbmj3qoe7Dv9DSl9pEZzEaWwcmcUO+9/uHHB4uuhmnD f1zp6bA/nUyeukkk8Ow1tHY3Ll1meE8szSbX5MQDJlU2SfAErxdE3mU4Hwu85kPUSG FwOvcOcQDZrBA== Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id 9z05xgmhd0z5; Wed, 27 Feb 2019 15:00:37 -0500 (EST) Received: from smarchi-efficios.internal.efficios.com (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id B2B9B807A6; Wed, 27 Feb 2019 15:00:37 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 01/13] Split rank_one_type_parm_ptr from rank_one_type Date: Wed, 27 Feb 2019 15:00:16 -0500 Message-Id: <20190227200028.27360-2-simon.marchi@efficios.com> In-Reply-To: <20190227200028.27360-1-simon.marchi@efficios.com> References: <20190227200028.27360-1-simon.marchi@efficios.com> MIME-Version: 1.0 gdb/ChangeLog: * gdbtypes.c (rank_one_type_parm_ptr): New function extracted from... (rank_one_type): ... this. --- gdb/gdbtypes.c | 136 ++++++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 63 deletions(-) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index b5f269241c..dc4ef56576 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3810,7 +3810,78 @@ type_not_associated (const struct type *type) return (prop && TYPE_DYN_PROP_KIND (prop) == PROP_CONST && !TYPE_DYN_PROP_ADDR (prop)); } - + +/* rank_one_type helper for when PARM's type code is TYPE_CODE_PTR. */ + +static struct rank +rank_one_type_parm_ptr (struct type *parm, struct type *arg, struct value *value) +{ + struct rank rank = {0,0}; + + switch (TYPE_CODE (arg)) + { + case TYPE_CODE_PTR: + + /* Allowed pointer conversions are: + (a) pointer to void-pointer conversion. */ + if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) + return VOID_PTR_CONVERSION_BADNESS; + + /* (b) pointer to ancestor-pointer conversion. */ + rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm), + TYPE_TARGET_TYPE (arg), + 0); + if (rank.subrank >= 0) + return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank); + + return INCOMPATIBLE_TYPE_BADNESS; + case TYPE_CODE_ARRAY: + { + struct type *t1 = TYPE_TARGET_TYPE (parm); + struct type *t2 = TYPE_TARGET_TYPE (arg); + + if (types_equal (t1, t2)) + { + /* Make sure they are CV equal. */ + if (TYPE_CONST (t1) != TYPE_CONST (t2)) + rank.subrank |= CV_CONVERSION_CONST; + if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2)) + rank.subrank |= CV_CONVERSION_VOLATILE; + if (rank.subrank != 0) + return sum_ranks (CV_CONVERSION_BADNESS, rank); + return EXACT_MATCH_BADNESS; + } + return INCOMPATIBLE_TYPE_BADNESS; + } + case TYPE_CODE_FUNC: + return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL); + case TYPE_CODE_INT: + if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT) + { + if (value_as_long (value) == 0) + { + /* Null pointer conversion: allow it to be cast to a pointer. + [4.10.1 of C++ standard draft n3290] */ + return NULL_POINTER_CONVERSION_BADNESS; + } + else + { + /* If type checking is disabled, allow the conversion. */ + if (!strict_type_checking) + return NS_INTEGER_POINTER_CONVERSION_BADNESS; + } + } + /* fall through */ + case TYPE_CODE_ENUM: + case TYPE_CODE_FLAGS: + case TYPE_CODE_CHAR: + case TYPE_CODE_RANGE: + case TYPE_CODE_BOOL: + default: + return INCOMPATIBLE_TYPE_BADNESS; + } +} + /* Compare one type (PARM) for compatibility with another (ARG). * PARM is intended to be the parameter type of a function; and * ARG is the supplied argument's type. This function tests if @@ -3901,68 +3972,7 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value) switch (TYPE_CODE (parm)) { case TYPE_CODE_PTR: - switch (TYPE_CODE (arg)) - { - case TYPE_CODE_PTR: - - /* Allowed pointer conversions are: - (a) pointer to void-pointer conversion. */ - if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) - return VOID_PTR_CONVERSION_BADNESS; - - /* (b) pointer to ancestor-pointer conversion. */ - rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm), - TYPE_TARGET_TYPE (arg), - 0); - if (rank.subrank >= 0) - return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank); - - return INCOMPATIBLE_TYPE_BADNESS; - case TYPE_CODE_ARRAY: - { - struct type *t1 = TYPE_TARGET_TYPE (parm); - struct type *t2 = TYPE_TARGET_TYPE (arg); - - if (types_equal (t1, t2)) - { - /* Make sure they are CV equal. */ - if (TYPE_CONST (t1) != TYPE_CONST (t2)) - rank.subrank |= CV_CONVERSION_CONST; - if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2)) - rank.subrank |= CV_CONVERSION_VOLATILE; - if (rank.subrank != 0) - return sum_ranks (CV_CONVERSION_BADNESS, rank); - return EXACT_MATCH_BADNESS; - } - return INCOMPATIBLE_TYPE_BADNESS; - } - case TYPE_CODE_FUNC: - return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL); - case TYPE_CODE_INT: - if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT) - { - if (value_as_long (value) == 0) - { - /* Null pointer conversion: allow it to be cast to a pointer. - [4.10.1 of C++ standard draft n3290] */ - return NULL_POINTER_CONVERSION_BADNESS; - } - else - { - /* If type checking is disabled, allow the conversion. */ - if (!strict_type_checking) - return NS_INTEGER_POINTER_CONVERSION_BADNESS; - } - } - /* fall through */ - case TYPE_CODE_ENUM: - case TYPE_CODE_FLAGS: - case TYPE_CODE_CHAR: - case TYPE_CODE_RANGE: - case TYPE_CODE_BOOL: - default: - return INCOMPATIBLE_TYPE_BADNESS; - } + return rank_one_type_parm_ptr (parm, arg, value); case TYPE_CODE_ARRAY: switch (TYPE_CODE (arg)) {