This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
RFC: C++ overloadin fixes and a type "char" tweak
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Wed, 8 Jan 2003 22:20:49 -0500
- Subject: RFC: C++ overloadin fixes and a type "char" tweak
I wanted to fish for comments on this patch. I don't know if
Ada/Java/whatever have a type named "char" that doesn't have the fancy
NOSIGN property, but the flag is only ever checked in the C++ overloader, so
it's safe. Basically two patches here:
- Mark a type named "char" as TYPE_FLAG_NOSIGN, and mark the character
type in stabs as NOSIGN. DWARF-2 does not have anything to express the
distinction, unfortunately, from my readings and examinations.
[The NOSIGN bit means nothing except in the C++ conversion rules.
Basically, char != signed char != unsigned char; char is used for certain
things, and has to be coerced to either of the others sometimes when
selecting a promotion for overloading.]
- Handle the tag names "unsigned" vs. "unsigned int" properly when
checking which overloaded function to call.
This gets all the tests in overload.exp passing, and removes some XPASSes
for g++2.95/stabs+.
Thoughts before I apply this, anyone?
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
2003-01-08 Daniel Jacobowitz <drow@mvista.com>
* gdbtypes.c (init_type): Mark "char" as TYPE_FLAG_NOSIGN.
(integer_types_same_name_p): New function.
(rank_one_type): Use it.
* stabsread.c (read_range_type): Mark "char" as TYPE_FLAG_NOSIGN.
2003-01-08 Daniel Jacobowitz <drow@mvista.com>
* gdb.c++/overload.exp: Remove some fixed XFAILs.
Index: gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.65
diff -u -p -r1.65 gdbtypes.c
--- gdbtypes.c 2 Jan 2003 14:27:26 -0000 1.65
+++ gdbtypes.c 8 Jan 2003 20:57:45 -0000
@@ -1874,6 +1874,9 @@ init_type (enum type_code code, int leng
/* C++ fancies. */
+ if (name && strcmp (name, "char") == 0)
+ TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN;
+
if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
{
INIT_CPLUS_SPECIFIC (type);
@@ -2441,6 +2444,43 @@ rank_function (struct type **parms, int
return bv;
}
+/* Compare the names of two integer types, assuming that any sign
+ qualifiers have been checked already. We do it this way because
+ there may be an "int" in the name of one of the types. */
+
+static int
+integer_types_same_name_p (const char *first, const char *second)
+{
+ int first_p, second_p;
+
+ /* If both are shorts, return 1; if neither is a short, keep checking. */
+ first_p = (strstr (first, "short") != NULL);
+ second_p = (strstr (second, "short") != NULL);
+ if (first_p && second_p)
+ return 1;
+ if (first_p || second_p)
+ return 0;
+
+ /* Likewise for long. */
+ first_p = (strstr (first, "long") != NULL);
+ second_p = (strstr (second, "long") != NULL);
+ if (first_p && second_p)
+ return 1;
+ if (first_p || second_p)
+ return 0;
+
+ /* Likewise for char. */
+ first_p = (strstr (first, "char") != NULL);
+ second_p = (strstr (second, "char") != NULL);
+ if (first_p && second_p)
+ return 1;
+ if (first_p || second_p)
+ return 0;
+
+ /* They must both be ints. */
+ return 1;
+}
+
/* 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
@@ -2557,16 +2597,19 @@ rank_one_type (struct type *parm, struct
{
if (TYPE_UNSIGNED (arg))
{
- if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
- return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
- else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
+ /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
+ if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
+ return 0;
+ else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
+ && integer_types_same_name_p (TYPE_NAME (parm), "long"))
return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
else
return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
}
else
{
- if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
+ if (integer_types_same_name_p (TYPE_NAME (arg), "long")
+ && integer_types_same_name_p (TYPE_NAME (parm), "int"))
return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
else
return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
@@ -2574,9 +2617,10 @@ rank_one_type (struct type *parm, struct
}
else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
{
- if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
+ if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg)))
return 0;
- else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
+ else if (integer_types_same_name_p (TYPE_NAME (arg), "int")
+ && integer_types_same_name_p (TYPE_NAME (parm), "long"))
return INTEGER_PROMOTION_BADNESS;
else
return INTEGER_COERCION_BADNESS;
Index: stabsread.c
===================================================================
RCS file: /cvs/src/src/gdb/stabsread.c,v
retrieving revision 1.49
diff -u -p -r1.49 stabsread.c
--- stabsread.c 5 Jan 2003 04:59:28 -0000 1.49
+++ stabsread.c 8 Jan 2003 20:57:47 -0000
@@ -4930,7 +4930,7 @@ read_range_type (char **pp, int typenums
/* Special case: char is defined (Who knows why) as a subrange of
itself with range 0-127. */
else if (self_subrange && n2 == 0 && n3 == 127)
- return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
+ return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile);
/* We used to do this only for subrange of self or subrange of int. */
else if (n2 == 0)
Index: testsuite/gdb.c++/overload.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.c++/overload.exp,v
retrieving revision 1.7
diff -u -p -r1.7 overload.exp
--- testsuite/gdb.c++/overload.exp 8 Jan 2002 05:37:43 -0000 1.7
+++ testsuite/gdb.c++/overload.exp 8 Jan 2003 21:02:17 -0000
@@ -260,13 +260,6 @@ gdb_expect {
}
-# The overload resolver added by HP (valops.c:find_overload_match) doesn't
-# work right for G++ output, since the list of parameters seems not to
-# be filled in correctly. Until this gets fixed, don't expect to pass
-# some of these tests.
-
-setup_xfail "*-*-*" CLLbs16901
-
send_gdb "print foo_instance1.overload1arg((short)arg5)\n"
gdb_expect {
-re ".\[0-9\]* = 5\r\n$gdb_prompt $" {
@@ -277,8 +270,6 @@ gdb_expect {
}
-setup_xfail "*-*-*" CLLbs16901
-
send_gdb "print foo_instance1.overload1arg((unsigned short)arg6)\n"
gdb_expect {
-re ".\[0-9\]* = 6\r\n$gdb_prompt $" {
@@ -309,8 +300,6 @@ gdb_expect {
}
-setup_xfail "*-*-*" CLLbs16901
-
send_gdb "print foo_instance1.overload1arg((long)arg9)\n"
gdb_expect {
-re ".\[0-9\]* = 9\r\n$gdb_prompt $" {
@@ -320,8 +309,6 @@ gdb_expect {
timeout { fail "(timeout) print call overloaded func long arg" }
}
-
-setup_xfail "*-*-*" CLLbs16901
send_gdb "print foo_instance1.overload1arg((unsigned long)arg10)\n"
gdb_expect {