diff options
author | Tom Tromey <tromey@adacore.com> | 2021-04-27 07:35:23 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2021-04-28 10:19:57 -0600 |
commit | db2534b704e5f1227decd2a0cfe62bff1d2bee65 (patch) | |
tree | 86db8952ae49240f8e209b74606ad43673d79ca9 /gdb/testsuite | |
parent | e43c3e2a741256e9520f59bd08d9e74f9da0c631 (diff) | |
download | binutils-db2534b704e5f1227decd2a0cfe62bff1d2bee65.zip binutils-db2534b704e5f1227decd2a0cfe62bff1d2bee65.tar.gz binutils-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/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/null_overload.exp | 37 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/null_overload/foo.adb | 42 |
3 files changed, 84 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index d2ed989..d4ed915 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2021-04-28 Tom Tromey <tromey@adacore.com> + + * gdb.ada/null_overload.exp: New file. + * gdb.ada/null_overload/foo.adb: New file. + 2021-04-28 Andrew Burgess <andrew.burgess@embecosm.com> * gdb.python/py-startup-opt.exp: New file. diff --git a/gdb/testsuite/gdb.ada/null_overload.exp b/gdb/testsuite/gdb.ada/null_overload.exp new file mode 100644 index 0000000..e5b40de --- /dev/null +++ b/gdb/testsuite/gdb.ada/null_overload.exp @@ -0,0 +1,37 @@ +# Copyright 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +load_lib "ada.exp" + +if { [skip_ada_tests] } { return -1 } + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test "print f(null)" " = true" +gdb_test "print f(r_access'(null))" " = true" +gdb_test "print f(0)" " = false" + +gdb_test "print null" " = null" +gdb_test "print/d null" " = 0" +gdb_test "print U_Ptr" " = \\\(access foo\\.u_0\\\) 0x0" diff --git a/gdb/testsuite/gdb.ada/null_overload/foo.adb b/gdb/testsuite/gdb.ada/null_overload/foo.adb new file mode 100644 index 0000000..9a18606 --- /dev/null +++ b/gdb/testsuite/gdb.ada/null_overload/foo.adb @@ -0,0 +1,42 @@ +-- Copyright 2021 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +procedure Foo is + + type R_Type is null record; + type R_Access is access R_Type; + + type U_0 is mod 1; + type U_P_T is access all U_0; + + function F (R : R_Access) return Boolean is + begin + return True; + end F; + + function F (I : Integer) return Boolean is + begin + return False; + end F; + + B1 : constant Boolean := F (null); + B2 : constant Boolean := F (0); + + U : U_0 := 0; + U_Ptr : U_P_T := null; + +begin + null; -- START +end Foo; |