From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CLIWOxHqjV89BAAAWB0awg (envelope-from ) for ; Mon, 19 Oct 2020 15:33:37 -0400 Received: by simark.ca (Postfix, from userid 112) id E56371EFBD; Mon, 19 Oct 2020 15:33:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7A3011EFB9 for ; Mon, 19 Oct 2020 15:33:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2ADC03844008; Mon, 19 Oct 2020 19:33:36 +0000 (GMT) Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 8EB9138618D4 for ; Mon, 19 Oct 2020 19:33:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8EB9138618D4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id F320511774D; Mon, 19 Oct 2020 15:33:31 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id xzlaylzoBoyn; Mon, 19 Oct 2020 15:33:31 -0400 (EDT) Received: from murgatroyd.Home (75-166-102-113.hlrn.qwest.net [75.166.102.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id AF6CB117710; Mon, 19 Oct 2020 15:33:31 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH] Don't inherit range-type signed-ness from underlying type Date: Mon, 19 Oct 2020 13:33:30 -0600 Message-Id: <20201019193330.3242805-1-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" A recent commit changed gdb to inherit the signed-ness of a range type from its underlying type: commit cfabbd351a174406fd5aa063303f5c8bf9266bbc Author: Tom Tromey Date: Sat Oct 17 11:41:59 2020 -0600 Make range types inherit signed-ness from base type This passed testing -- but unfortunately, additional testing at AdaCore showed that this change was incorrect. GNAT, at least, can emit an unsigned range type whose underlying type is signed. This patch reverts the code change from the above. I chose not to reintroduce the FIXME comments, because now we know that they are incorrect. Instead, this patch also adds a comment to create_range_type. A new test case is included as well. gdb/ChangeLog 2020-10-19 Tom Tromey * gdbtypes.c (create_range_type): Revert previous patch. Add comment. gdb/testsuite/ChangeLog 2020-10-19 Tom Tromey * gdb.ada/unsigned_range/foo.adb: New file. * gdb.ada/unsigned_range/pack.adb: New file. * gdb.ada/unsigned_range/pack.ads: New file. * gdb.ada/unsigned_range.exp: New file. --- gdb/ChangeLog | 5 +++ gdb/gdbtypes.c | 16 +++++++- gdb/testsuite/ChangeLog | 7 ++++ gdb/testsuite/gdb.ada/unsigned_range.exp | 32 +++++++++++++++ gdb/testsuite/gdb.ada/unsigned_range/foo.adb | 39 +++++++++++++++++++ gdb/testsuite/gdb.ada/unsigned_range/pack.adb | 23 +++++++++++ gdb/testsuite/gdb.ada/unsigned_range/pack.ads | 19 +++++++++ 7 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.ada/unsigned_range.exp create mode 100644 gdb/testsuite/gdb.ada/unsigned_range/foo.adb create mode 100644 gdb/testsuite/gdb.ada/unsigned_range/pack.adb create mode 100644 gdb/testsuite/gdb.ada/unsigned_range/pack.ads diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index e7d9e4cef3e..2c3ef65e13d 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -950,7 +950,21 @@ create_range_type (struct type *result_type, struct type *index_type, result_type->set_bounds (bounds); - result_type->set_is_unsigned (index_type->is_unsigned ()); + /* Note that the signed-ness of a range type can't simply be copied + from the underlying type. GNAT, at least, can emit an unsigned + range whose underlying type is signed. This matters if values + from the range are stored in a bitfield, because in this case + sign extension would result in the wrong value. So, we have some + heuristics here instead. */ + if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0) + result_type->set_is_unsigned (true); + /* Ada allows the declaration of range types whose upper bound is + less than the lower bound, so checking the lower bound is not + enough. Make sure we do not mark a range type whose upper bound + is negative as unsigned. */ + if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0) + result_type->set_is_unsigned (false); + result_type->set_endianity_is_not_default (index_type->endianity_is_not_default ()); diff --git a/gdb/testsuite/gdb.ada/unsigned_range.exp b/gdb/testsuite/gdb.ada/unsigned_range.exp new file mode 100644 index 00000000000..476aa8ba3c9 --- /dev/null +++ b/gdb/testsuite/gdb.ada/unsigned_range.exp @@ -0,0 +1,32 @@ +# Copyright 2020 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 . + +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 "BREAK" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test "print Value" \ + [string_to_regexp " = (one => 8000, two => 51000)"] diff --git a/gdb/testsuite/gdb.ada/unsigned_range/foo.adb b/gdb/testsuite/gdb.ada/unsigned_range/foo.adb new file mode 100644 index 00000000000..52c669acc8b --- /dev/null +++ b/gdb/testsuite/gdb.ada/unsigned_range/foo.adb @@ -0,0 +1,39 @@ +-- Copyright 2020 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 . + +with Pack; use Pack; + +procedure Foo is + type U_W is range 0 .. 65535; + for U_W'Size use 16; + + type R_C is + record + One : U_W; + Two : U_W; + end record; + + for R_C use + record at mod 2; + One at 0 range 0 .. 15; + Two at 2 range 0 .. 15; + end record; + for R_C'size use 2*16; + + Value: R_C := (One => 8000, Two => 51000); + +begin + Do_Nothing (Value'Address); -- BREAK +end Foo; diff --git a/gdb/testsuite/gdb.ada/unsigned_range/pack.adb b/gdb/testsuite/gdb.ada/unsigned_range/pack.adb new file mode 100644 index 00000000000..626ea6044ea --- /dev/null +++ b/gdb/testsuite/gdb.ada/unsigned_range/pack.adb @@ -0,0 +1,23 @@ +-- Copyright 2020 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 . + +package body Pack is + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + +end Pack; diff --git a/gdb/testsuite/gdb.ada/unsigned_range/pack.ads b/gdb/testsuite/gdb.ada/unsigned_range/pack.ads new file mode 100644 index 00000000000..f744c538b47 --- /dev/null +++ b/gdb/testsuite/gdb.ada/unsigned_range/pack.ads @@ -0,0 +1,19 @@ +-- Copyright 2020 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 . + +with System; +package Pack is + procedure Do_Nothing (A : System.Address); +end Pack; -- 2.26.2