[PING,v1,0/2] Fix the right shift of negative numbers

Message ID Zho3IAwwivhyDeLn@gentoo
State New
Headers

Commit Message

Sergey Kaplun April 13, 2024, 7:41 a.m. UTC
  Hi, folks!
I am looking forward to your reply!

Should I create an issue related to this patchset?

Also, for these 2 weeks, I've dived a bit into the problems around
OpenCL and CI failures (see links below) and need help with the
following questions:

Since commit 63c457b91104 ("gmp-utils: protect gdb_mpz exports against
out-of-range values"), the subtest max-uint64 of the enabled test fails
[1] on a 32-bit arm since "the 0xffffffffffffffff value cannot be
represented as 32-bit unsigned integer". Should I disable this test for
the 32-bit arm, or skip it somehow?

Also, on the aarch64, the subtest "-1 >> 1" fails [2] before the fix in
the second commit. Should I squash the commits to avoid regressions
between commits?

Plus, I've dived a bit into OpenCL failures. After the commit
55fc1623f942 ("Add name canonicalization for C") the corresponding
OpenCL cast fails with the error:

| gdb -ex 'set language opencl' -ex 'p (signed char) 1' -ex 'quit'
| ...
| No type named signed char.

Since for OpenCL "signed char" is valid [3] and looks like it is the
same type as just "char" [4], it should be fixed like the following:

===================================================================
===================================================================

But even if I ran the executable from the directory with the
datatypes.cl file, I got the following errors:
| clBuildProgram failed with:
| 1:116:16: error: double precision constant requires cl_khr_fp64, casting to single precision
|   half   h   = 1.0;
|                ^
| 1:117:25: error: double precision constant requires cl_khr_fp64, casting to single precision
|   half2  h2  = (half2) (1.0, 2.0);
|                         ^
| ...

If I remove the ".0" parts, then it runs OK, but I still can't set a
breakpoint on the `testkernel`. I'm kind of stuck here and don't know
what to do.

[1]: https://ci.linaro.org/job/tcwg_gdb_check--master-arm-precommit/2073/artifact/artifacts/artifacts.precommit/notify/
[2]: https://ci.linaro.org/job/tcwg_gdb_check--master-aarch64-precommit/2072/artifact/artifacts/artifacts.precommit/notify/
[3]: https://godbolt.org/z/obPGdses6
[4]: https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#built-in-scalar-data-types
  

Patch

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1e1a7e9ce61..8dc1872849d 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1684,8 +1684,9 @@  lookup_unsigned_typename (const struct language_defn *language,
 struct type *
 lookup_signed_typename (const struct language_defn *language, const char *name)
 {
-  /* In C and C++, "char" and "signed char" are distinct types.  */
-  if (streq (name, "char"))
+  /* In C and C++, "char" and "signed char" are distinct types.
+     But not in OpenCL.  */
+  if (streq (name, "char") && language->la_language != language_opencl)
     name = "signed char";
   return lookup_typename (language, name, NULL, 0);
 }
diff --git a/gdb/testsuite/gdb.opencl/datatypes.cl b/gdb/testsuite/gdb.opencl/datatypes.cl
index 999defa38b4..d390eb02b3f 100644
--- a/gdb/testsuite/gdb.opencl/datatypes.cl
+++ b/gdb/testsuite/gdb.opencl/datatypes.cl
@@ -46,6 +46,8 @@  __kernel void testkernel (__global int *data)
   char8  c8  = (char8) (1, 2, 3, 4, 5, 6, 7, 8);
   char16 c16 = (char16)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
 
+  signed char c_signed = 1;
+
   uchar   uc   = 1;
   uchar2  uc2  = (uchar2) (1, 2);
 #ifdef CL_VERSION_1_1
diff --git a/gdb/testsuite/gdb.opencl/datatypes.exp b/gdb/testsuite/gdb.opencl/datatypes.exp
index 16243ad3cfb..c47c4873421 100644
--- a/gdb/testsuite/gdb.opencl/datatypes.exp
+++ b/gdb/testsuite/gdb.opencl/datatypes.exp
@@ -53,6 +53,9 @@  gdb_test "p sizeof(char8)" " = 8"
 gdb_test "whatis char16" "type = char16"
 gdb_test "p sizeof(char16)" " = 16"
 
+gdb_test "whatis signed char" "type = char"
+gdb_test "p sizeof(signed char)" " = 1"
+
 gdb_test "whatis unsigned char" "type = unsigned char"
 gdb_test "p sizeof(unsigned char)" " = 1"
 gdb_test "whatis uchar" "type = uchar"
@@ -247,6 +250,10 @@  gdb_test "whatis c16" "type = char16"
 gdb_test "p sizeof(c16)" " = 16"
 gdb_test "print c16" " = \\{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16\\}"
 
+gdb_test "whatis c_signed" "type = char"
+gdb_test "p sizeof(c_signed)" " = 1"
+gdb_test "print/d c_signed" " = 1"
+
 gdb_test "whatis uc" "type = uchar"
 gdb_test "p sizeof(uc)" " = 1"
 gdb_test "print/d uc" " = 1"
===================================================================

Also, locally, I've tracked down that the OpenCL tests are skipped due
to the following warnings:

| /home/burii/binutils-gdb-master/gdb/testsuite/lib/cl_util.c:371:70: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t' {aka 'long unsigned int'} [-Wformat=]
|   371 |               printf ("    CL_DEVICE_IMAGE3D_MAX_DEPTH:             %d\n", sizet);
|       |                                                                     ~^     ~~~~~
|       |                                                                      |     |
|       |                                                                      int   size_t {aka long unsigned int}
|       |                                                                     %ld
| In file included from /usr/include/CL/cl.h:20,
|                  from /home/burii/binutils-gdb-master/gdb/testsuite/lib/opencl_hostapp.c:28:
| /usr/include/CL/cl_version.h:22:9: note: '#pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)'
|    22 | #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 300 (OpenCL 3.0)")
|       |         ^~~~~~~
| /home/burii/binutils-gdb-master/gdb/testsuite/lib/opencl_hostapp.c: In function 'main':
| /home/burii/binutils-gdb-master/gdb/testsuite/lib/opencl_hostapp.c:81:3: warning: 'clCreateCommandQueue' is deprecated [-Wdeprecated-declarations]
|    81 |   queue = clCreateCommandQueue (context, device, 0, &err);
|       |   ^~~~~
| /usr/include/CL/cl.h:1920:1: note: declared here
|  1920 | clCreateCommandQueue(cl_context                     context,
|       | ^~~~~~~~~~~~~~~~~~~~

Since the output of the CC command isn't empty, the OpenCL suite is
declared unsupported. I added the following hotfix to run tests:

===================================================================
diff --git a/gdb/testsuite/lib/opencl.exp b/gdb/testsuite/lib/opencl.exp
index caa0e1e2911..7d2316edad7 100644
--- a/gdb/testsuite/lib/opencl.exp
+++ b/gdb/testsuite/lib/opencl.exp
@@ -23,6 +23,7 @@  proc gdb_compile_opencl_hostapp {clsource executable options} {
     set src "${srcdir}/lib/cl_util.c ${srcdir}/lib/opencl_hostapp.c"
     set binfile [standard_output_file ${executable}]
     set compile_flags [concat additional_flags=-I${srcdir}/lib/ additional_flags=-DCL_SOURCE=$clsource]
+    set compile_flags [concat $compile_flags additional_flags=-DCL_TARGET_OPENCL_VERSION=300 additional_flags=-w]
     set options_opencl [concat {debug} $compile_flags $options [list libs=-lOpenCL]]
     return [gdb_compile ${src} ${binfile} "executable" ${options_opencl}]
 }
===================================================================

Then I run the testcase like the following, with the result:
| make check TESTS="gdb.opencl/datatypes.exp" | grep FAIL
| WARNING: Couldn't find the global config file.
| FAIL: gdb.opencl/datatypes.exp: whatis char16
| FAIL: gdb.opencl/datatypes.exp: p sizeof(char16)
| FAIL: gdb.opencl/datatypes.exp: whatis uchar16
| FAIL: gdb.opencl/datatypes.exp: p sizeof(uchar16)
| ... all 16-bit values fail
| ERROR: (datatypes) No such file or directory
| FAIL: gdb.opencl/datatypes.exp: run
| .. all after it fail

To make this work, I've added the following fix:
===================================================================
diff --git a/gdb/testsuite/gdb.opencl/datatypes.exp b/gdb/testsuite/gdb.opencl/datatypes.exp
index 16243ad3cfb..539099d9c0f 100644
--- a/gdb/testsuite/gdb.opencl/datatypes.exp
+++ b/gdb/testsuite/gdb.opencl/datatypes.exp
@@ -22,10 +22,11 @@  load_lib opencl.exp
 require allow_opencl_tests
 
 set testfile "datatypes"
-set clprogram [remote_download target ${srcdir}/${subdir}/${testfile}.cl]
+set clsource ${srcdir}/${subdir}/${testfile}.cl
+set clprogram [remote_download target ${clsource}]
 
 # Compile the generic OpenCL host app
-if { [gdb_compile_opencl_hostapp "${clprogram}" "${testfile}" "" ] != "" } {
+if { [gdb_compile_opencl_hostapp "${clsource}" "${testfile}" "" ] != "" } {
     untested "failed to compile"
     return -1
 }
@@ -197,7 +201,7 @@  gdb_test_no_output "set language auto" "no prompt when setting the language to a
 
 # Load the OpenCL app
 gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${objdir}/${subdir}/${testfile}
+gdb_load ${objdir}/outputs/${subdir}/${testfile}/${testfile}
 
 # Set breakpoint at the OpenCL kernel
 gdb_test "tbreak testkernel" \