aboutsummaryrefslogtreecommitdiff
path: root/gdb/ada-lang.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-04-27 07:35:23 -0600
committerTom Tromey <tromey@adacore.com>2021-04-28 10:19:57 -0600
commitdb2534b704e5f1227decd2a0cfe62bff1d2bee65 (patch)
tree86db8952ae49240f8e209b74606ad43673d79ca9 /gdb/ada-lang.c
parente43c3e2a741256e9520f59bd08d9e74f9da0c631 (diff)
downloadgdb-db2534b704e5f1227decd2a0cfe62bff1d2bee65.zip
gdb-db2534b704e5f1227decd2a0cfe62bff1d2bee65.tar.gz
gdb-db2534b704e5f1227decd2a0cfe62bff1d2bee65.tar.bz2
Fix Ada overloading with 'null'
Currently, the Ada expression parser treats 'null' as an integer 0. However, this causes overloading to fail in certain cases. This patch changes the Ada expression parser to use a special type for 'null'. I chose pointer-to-int0, because I think that's not likely to be needed for any other Ada expression. Note this works because a "mod 1" type has an underlying non-zero byte size; the test includes a check for this. The output is changed so that "print null", by default, shows "null". And, ada_type_match is changed both to recognize the special null type and to remove a bit of weird code related to how pointers are treated for overload type matching. Tested on x86-64 Fedora 32. Because this only touches Ada, and Joel already approved it internally at AdaCore, I am checking it in. gdb/ChangeLog 2021-04-28 Tom Tromey <tromey@adacore.com> * ada-exp.y (primary): Use new type for null pointer. * ada-lang.c (ada_type_match): Remove "may_deref" parameter. Handle null pointer. (ada_args_match): Update. * ada-valprint.c (ada_value_print_ptr, ada_value_print): Handle null pointer. gdb/testsuite/ChangeLog 2021-04-28 Tom Tromey <tromey@adacore.com> * gdb.ada/null_overload.exp: New file. * gdb.ada/null_overload/foo.adb: New file.
Diffstat (limited to 'gdb/ada-lang.c')
-rw-r--r--gdb/ada-lang.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 28f14c9..0b50a78 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -95,8 +95,6 @@ static struct type *desc_index_type (struct type *, int);
static int desc_arity (struct type *);
-static int ada_type_match (struct type *, struct type *, int);
-
static int ada_args_match (struct symbol *, struct value **, int);
static struct value *make_array_descriptor (struct type *, struct value *);
@@ -3492,14 +3490,12 @@ ada_resolve_variable (struct symbol *sym, const struct block *block,
return candidates[i];
}
-/* Return non-zero if formal type FTYPE matches actual type ATYPE. If
- MAY_DEREF is non-zero, the formal may be a pointer and the actual
- a non-pointer. */
+/* Return non-zero if formal type FTYPE matches actual type ATYPE. */
/* The term "match" here is rather loose. The match is heuristic and
liberal. */
static int
-ada_type_match (struct type *ftype, struct type *atype, int may_deref)
+ada_type_match (struct type *ftype, struct type *atype)
{
ftype = ada_check_typedef (ftype);
atype = ada_check_typedef (atype);
@@ -3514,12 +3510,13 @@ ada_type_match (struct type *ftype, struct type *atype, int may_deref)
default:
return ftype->code () == atype->code ();
case TYPE_CODE_PTR:
- if (atype->code () == TYPE_CODE_PTR)
- return ada_type_match (TYPE_TARGET_TYPE (ftype),
- TYPE_TARGET_TYPE (atype), 0);
- else
- return (may_deref
- && ada_type_match (TYPE_TARGET_TYPE (ftype), atype, 0));
+ if (atype->code () != TYPE_CODE_PTR)
+ return 0;
+ atype = TYPE_TARGET_TYPE (atype);
+ /* This can only happen if the actual argument is 'null'. */
+ if (atype->code () == TYPE_CODE_INT && TYPE_LENGTH (atype) == 0)
+ return 1;
+ return ada_type_match (TYPE_TARGET_TYPE (ftype), atype);
case TYPE_CODE_INT:
case TYPE_CODE_ENUM:
case TYPE_CODE_RANGE:
@@ -3580,7 +3577,7 @@ ada_args_match (struct symbol *func, struct value **actuals, int n_actuals)
struct type *ftype = ada_check_typedef (func_type->field (i).type ());
struct type *atype = ada_check_typedef (value_type (actuals[i]));
- if (!ada_type_match (ftype, atype, 1))
+ if (!ada_type_match (ftype, atype))
return 0;
}
}