public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
From: gdb-buildbot@sergiodj.net
To: gdb-testers@sourceware.org
Subject: [binutils-gdb] Fix bugs in 'val and 'pos with range types
Date: Mon, 22 Jun 2020 04:37:50 -0400	[thread overview]
Message-ID: <0bc2354b811e913b39c288e74d7166eaa3639309@gdb-build> (raw)

*** TEST RESULTS FOR COMMIT 0bc2354b811e913b39c288e74d7166eaa3639309 ***

commit 0bc2354b811e913b39c288e74d7166eaa3639309
Author:     Tom Tromey <tromey@adacore.com>
AuthorDate: Tue May 26 14:11:08 2020 -0600
Commit:     Tom Tromey <tromey@adacore.com>
CommitDate: Tue May 26 14:11:08 2020 -0600

    Fix bugs in 'val and 'pos with range types
    
    In Ada, the 'val and 'pos attributes can be used to map from an
    enumeration constant to its position in the enum and vice versa.
    These operators did not work properly when the type in question was a
    subrange of an enum type with "holes".
    
    gdb/ChangeLog
    2020-05-26  Tom Tromey  <tromey@adacore.com>
    
            * ada-lang.c (value_val_atr): Handle TYPE_CODE_RANGE.
            * gdbtypes.c (discrete_position): Handle TYPE_CODE_RANGE.
    
    gdb/testsuite/ChangeLog
    2020-05-26  Tom Tromey  <tromey@adacore.com>
    
            * gdb.ada/arr_acc_idx_w_gap.exp: Add enum subrange tests.
            * gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads (Enum_Subrange): New
            type.
            * gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb (V): New
            variable.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 2e21613640..00d36ab767 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-26  Tom Tromey  <tromey@adacore.com>
+
+	* ada-lang.c (value_val_atr): Handle TYPE_CODE_RANGE.
+	* gdbtypes.c (discrete_position): Handle TYPE_CODE_RANGE.
+
 2020-05-25  Cristiano De Alti  <cristiano_dealti@hotmail.com>
 
 	PR gdb/13519
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7522917401..5ffb2d6ac9 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -9148,6 +9148,9 @@ value_val_atr (struct type *type, struct value *arg)
   if (!integer_type_p (value_type (arg)))
     error (_("'VAL requires integral argument"));
 
+  if (type->code () == TYPE_CODE_RANGE)
+    type = TYPE_TARGET_TYPE (type);
+
   if (type->code () == TYPE_CODE_ENUM)
     {
       long pos = value_as_long (arg);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 4fe8d9a8e9..2ee69899a9 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1155,6 +1155,9 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
 int
 discrete_position (struct type *type, LONGEST val, LONGEST *pos)
 {
+  if (type->code () == TYPE_CODE_RANGE)
+    type = TYPE_TARGET_TYPE (type);
+
   if (type->code () == TYPE_CODE_ENUM)
     {
       int i;
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 50473fc96e..0cc377f56e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-05-26  Tom Tromey  <tromey@adacore.com>
+
+	* gdb.ada/arr_acc_idx_w_gap.exp: Add enum subrange tests.
+	* gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads (Enum_Subrange): New
+	type.
+	* gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb (V): New
+	variable.
+
 2020-05-26  Christian Biesinger  <cbiesinger@google.com>
 
 	* Makefile.in: Use = instead of == for the test command
diff --git a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
index fd7ac44cb0..c08070ea53 100644
--- a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
+++ b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap.exp
@@ -53,3 +53,7 @@ gdb_test "print indexed_by_enum(lit2..lit4)" \
          " = \\(lit2 => 43, 42, 41\\)"
 gdb_test "print s(2..4)" \
          " = \"ell\""
+
+gdb_test "print v" " = lit3"
+gdb_test "print enum_subrange'pos(v)" " = 3"
+gdb_test "print enum_subrange'val(3)" " = lit3"
diff --git a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads
index 6e073e88a4..719380077e 100644
--- a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads
+++ b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap.ads
@@ -34,14 +34,16 @@ package Enum_With_Gap is
      );
    for Enum_With_Gaps'size use 16;
 
+   type Enum_Subrange is new Enum_With_Gaps range Lit1 .. Lit3;
+
    type MyWord is range 0 .. 16#FFFF# ;
    for MyWord'Size use 16;
 
    type AR is array (Enum_With_Gaps range <>) of MyWord;
    type AR_Access is access AR;
-   
+
    type String_Access is access String;
-   
+
    procedure Do_Nothing (E : AR_Access);
    procedure Do_Nothing (E : String_Access);
 
diff --git a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb
index da37dd7d5e..752b883798 100644
--- a/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb
+++ b/gdb/testsuite/gdb.ada/arr_acc_idx_w_gap/enum_with_gap_main.adb
@@ -19,6 +19,7 @@ procedure Enum_With_Gap_Main is
    Indexed_By_Enum : AR_Access :=
      new AR'(LIT1 => 1,  LIT2 => 43, LIT3 => 42, LIT4 => 41);
    S : String_Access := new String'("Hello!");
+   V : Enum_Subrange := LIT3;
 begin
    Do_Nothing (Indexed_By_Enum); --  BREAK
    Do_Nothing (S);


             reply	other threads:[~2020-06-22  8:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-22  8:37 gdb-buildbot [this message]
2020-06-22  8:37 ` Failures on Fedora-i686, branch master gdb-buildbot
2020-06-22  9:11 ` Failures on Fedora-x86_64-cc-with-index, " gdb-buildbot
2020-06-22  9:12 ` Failures on Fedora-x86_64-m32, " gdb-buildbot
2020-06-22  9:57 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " gdb-buildbot
2020-06-22 10:30 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot
2020-06-22 10:34 ` Failures on Fedora-x86_64-native-gdbserver-m32, " gdb-buildbot
2020-06-22 11:09 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0bc2354b811e913b39c288e74d7166eaa3639309@gdb-build \
    --to=gdb-buildbot@sergiodj.net \
    --cc=gdb-testers@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).