public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Kaplun <sergey_v_kaplun@mail.ru>
To: gdb-patches@sourceware.org
Cc: Sergey Kaplun <sergey_v_kaplun@mail.ru>
Subject: [PATCH v1 1/2] gdb/testsuite: enable back gdb.base/bitshift.exp
Date: Tue,  2 Apr 2024 23:17:57 +0300	[thread overview]
Message-ID: <60f4aaac945cdae542fd92bc61b6d8fb828fa80a.1712086444.git.sergey_v_kaplun@mail.ru> (raw)
In-Reply-To: <cover.1712086444.git.sergey_v_kaplun@mail.ru>

Since commit cdd4206647d0 ("gdb/testsuite: fix "continue outside of
loop" TCL errors"), all tests in gdb.base/bitshift.exp are skipped due
to an early return after matching the "ada" language.

This patch enables all tests and adds "opencl" to the skip list since
some test cases aren't handled correctly for it.

Also, since commit 303a881f8789 ("Use gdb_gmp for scalar arithmetic"),
0 instead of -1 is returned for signed negative values shifted by a
negative number, which contradicts Go semantics.  So, this patch fixes
the semantics and restores the deleted comment.
---
 gdb/testsuite/gdb.base/bitshift.exp |  4 ++--
 gdb/valarith.c                      | 11 ++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.base/bitshift.exp b/gdb/testsuite/gdb.base/bitshift.exp
index cfb1e7b9820..806886cc1bf 100644
--- a/gdb/testsuite/gdb.base/bitshift.exp
+++ b/gdb/testsuite/gdb.base/bitshift.exp
@@ -175,10 +175,10 @@ proc test_shifts {} {
 
     foreach_with_prefix lang $supported_langs {
 	set skip_langs {
-	    "unknown" "ada" "modula-2" "pascal" "fortran"
+	    "ada" "fortran" "modula-2" "opencl" "pascal" "unknown"
 	}
 	if {[lsearch -exact $skip_langs $lang] >= 0} {
-	    return
+	    continue
 	}
 
 	gdb_test_no_output "set language $lang"
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 6b152cadcac..50ef6d2b92e 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -1302,7 +1302,16 @@ scalar_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
 	  {
 	    unsigned long nbits;
 	    if (!check_valid_shift_count (op, result_type, type2, v2, nbits))
-	      v = 0;
+	      /* Pretend the too-large shift was decomposed in a
+	         number of smaller shifts.  An arithmetic signed
+	         right shift of a negative number always yields -1
+	         with such semantics.  This is the right thing to
+	         do for Go, and we might as well do it for
+	         languages where it is undefined.  Also, pretend a
+	         shift by a negative number was a shift by the
+	         negative number cast to unsigned, which is the
+	         same as shifting by a too-large number.  */
+	      v = (!result_type->is_unsigned () && v1 < 0) ? -1 : 0;
 	    else
 	      v = v1 >> nbits;
 	  }
-- 
2.43.2


  reply	other threads:[~2024-04-02 20:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 20:17 [PATCH v1 0/2] Fix the right shift of negative numbers Sergey Kaplun
2024-04-02 20:17 ` Sergey Kaplun [this message]
2024-04-02 20:17 ` [PATCH v1 2/2] " Sergey Kaplun
2024-04-13  7:41 ` [PING] [PATCH v1 0/2] " Sergey Kaplun
2024-04-23  8:45 ` [PING*2][PATCH " Sergey Kaplun
2024-04-23 14:46   ` Tom Tromey
2024-04-25 13:23     ` Sergey Kaplun

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=60f4aaac945cdae542fd92bc61b6d8fb828fa80a.1712086444.git.sergey_v_kaplun@mail.ru \
    --to=sergey_v_kaplun@mail.ru \
    --cc=gdb-patches@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).