[PATCH v1 1/2] gdb/testsuite: enable back gdb.base/bitshift.exp

Sergey Kaplun
2024-04-02T20:18:33Z

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