From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14709 invoked by alias); 11 Oct 2011 19:16:03 -0000 Received: (qmail 14699 invoked by uid 22791); 11 Oct 2011 19:16:02 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Oct 2011 19:15:43 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9BJFg97014911 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Oct 2011 15:15:42 -0400 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9BJFekm017895 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Tue, 11 Oct 2011 15:15:41 -0400 Message-ID: <4E9495DB.8010109@redhat.com> Date: Tue, 11 Oct 2011 19:16:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0) Gecko/20110927 Thunderbird/7.0 MIME-Version: 1.0 To: "gdb-patches@sourceware.org ml" Subject: [RFA] c++/13225 Content-Type: multipart/mixed; boundary="------------060204060308030803010409" X-IsSubscribed: yes 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 X-SW-Source: 2011-10/txt/msg00327.txt.bz2 This is a multi-part message in MIME format. --------------060204060308030803010409 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1631 Hi, This bug exposes two problems with inferior function calling. First (and foremost), the user is attempting to do something like: (gdb) p my_function $1 = ... my_function (char *) (gdb) p my_function(0) Cannot resolve function my_function to any overloaded instance This occurs because the parser interprets "0" as an integer, and the evaluator does not allow integer to pointer conversion. I cannot really think of a reason why gdb shouldn't be more permissive of this, as long as the INT will fit into a pointer. Second, for a function which takes multiple arguments, classify_oload_match would not inspect all arguments. Instead it would return immediately upon finding any INCOMPATIBLE or NONSTANDARD ranking. For incompatible, this is okay -- subsequent arguments' ranks don't matter anymore. However if we find NONSTANDARD, that doesn't mean that subsequent arguments' rankings should be dismissed, since one of these could be INCOMPATIBLE. Tested on x86_64 with no regressions. Keith ChangeLog 2011-10-11 Keith Seitz c++/13225 * gdbtypes.h (NS_POINTER_CONVERSION_BADNESS): Update comment. * gdbtypes.c (rank_one_type): Size permitting, allow int to pointer conversion. * valops.c (classify_oload_match): Inspect all arguments until INCOMPATIBLE is found. Return the worst badness found otherwise. testsuite/ChangeLog: 2011-10-11 Keith Seitz c++/13225 * gdb.cp/converts.cc (foo3_1): New function. * gdb.cp/converts.exp: Add test for int to pointer conversion. Add test to check if all arguments are checked for incompatible conversion BADNESS. --------------060204060308030803010409 Content-Type: text/x-patch; name="13225.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="13225.patch" Content-length: 3529 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index b1dada5..ca1547a 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -2470,6 +2470,11 @@ rank_one_type (struct type *parm, struct type *arg) case TYPE_CODE_FUNC: return rank_one_type (TYPE_TARGET_TYPE (parm), arg); case TYPE_CODE_INT: + /* The parser may return an integer type for a pointer, especially + if that pointer is 0 (aka NULL). Allow this if it will fit. */ + if (TYPE_LENGTH (parm) >= TYPE_LENGTH (arg)) + return NS_POINTER_CONVERSION_BADNESS; + /* fall through */ case TYPE_CODE_ENUM: case TYPE_CODE_FLAGS: case TYPE_CODE_CHAR: diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 9d9785b..fa6b43c 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1557,7 +1557,8 @@ extern const struct rank BASE_CONVERSION_BADNESS; extern const struct rank REFERENCE_CONVERSION_BADNESS; /* Non-standard conversions allowed by the debugger */ -/* Converting a pointer to an int is usually OK. */ +/* Converting a pointer to an int is usually OK. Also allow + an int to be converted into a pointer. */ extern const struct rank NS_POINTER_CONVERSION_BADNESS; diff --git a/gdb/valops.c b/gdb/valops.c index e88e9dc..b15d12f 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -3081,6 +3081,7 @@ classify_oload_match (struct badness_vector *oload_champ_bv, int static_offset) { int ix; + enum oload_classification worst = STANDARD; for (ix = 1; ix <= nargs - static_offset; ix++) { @@ -3093,11 +3094,13 @@ classify_oload_match (struct badness_vector *oload_champ_bv, NS_POINTER_CONVERSION_BADNESS or worse return NON_STANDARD. */ else if (compare_ranks (oload_champ_bv->rank[ix], NS_POINTER_CONVERSION_BADNESS) <= 0) - return NON_STANDARD; /* Non-standard type conversions + worst = NON_STANDARD; /* Non-standard type conversions needed. */ } - return STANDARD; /* Only standard conversions needed. */ + /* If no INCOMPATIBLE classification was found, return the worst one + that was found (if any). */ + return worst; } /* C++: return 1 is NAME is a legitimate name for the destructor of diff --git a/gdb/testsuite/gdb.cp/converts.cc b/gdb/testsuite/gdb.cp/converts.cc index 34b6927..772510a 100644 --- a/gdb/testsuite/gdb.cp/converts.cc +++ b/gdb/testsuite/gdb.cp/converts.cc @@ -23,6 +23,8 @@ int foo2_2 (char[][1]) {return 22;} int foo2_3 (char *[]) {return 23;} int foo2_4 (int *[]) {return 24;} +int foo3_1 (int a, const char **b) { return 31; } + int main() { @@ -53,5 +55,8 @@ int main() foo2_2 (ba); // ..array of arrays foo2_3 (b); // ..array of pointers foo2_4 ((int**)b); // ..array of wrong pointers + + foo3_1 (0, 0); // int to pointer + return 0; // end of main } diff --git a/gdb/testsuite/gdb.cp/converts.exp b/gdb/testsuite/gdb.cp/converts.exp index 3f3b3c8..a3d375b 100644 --- a/gdb/testsuite/gdb.cp/converts.exp +++ b/gdb/testsuite/gdb.cp/converts.exp @@ -49,3 +49,8 @@ gdb_test "p foo2_1 (b)" "= 21" "pointer pointer to pointer pointer" gdb_test "p foo2_2 (b)" "Cannot resolve.*" "pointer pointer to array of arrays" gdb_test "p foo2_3 (b)" "= 23" "pointer pointer to array of pointers" gdb_test "p foo2_4 (b)" "Cannot resolve.*" "pointer pointer to array of wrong pointers" + +gdb_test "p foo3_1 ((char *) 0, ta)" "Cannot resolve.*" \ + "check all parameters for badness" + +gdb_test "p foo3_1 (0, 0)" "= 31" "int to pointer conversion" --------------060204060308030803010409--