From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id C9FBB3858D33; Sun, 8 May 2022 17:38:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9FBB3858D33 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Fix gdb.cp/casts.exp with -m32 X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 603df41b467152a226419a8dd5949f98a746a86e X-Git-Newrev: a1aaf801d5f0989ea0857dfd896830570603b523 Message-Id: <20220508173818.C9FBB3858D33@sourceware.org> Date: Sun, 8 May 2022 17:38:18 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 May 2022 17:38:18 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da1aaf801d5f0= 989ea0857dfd896830570603b523 commit a1aaf801d5f0989ea0857dfd896830570603b523 Author: Tom de Vries Date: Sun May 8 19:38:13 2022 +0200 [gdb/testsuite] Fix gdb.cp/casts.exp with -m32 =20 When running test-case gdb.cp/casts.exp with target board unix/-m32, I = run into: ... (gdb) print (unsigned long long) &gd =3D=3D gd_value^M $31 =3D false^M (gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd =3D=3D gd_= value ... =20 With some additional printing, we can see in more detail why the compar= ison fails: ... (gdb) print /x &gd^M $31 =3D 0xffffc5c8^M (gdb) PASS: gdb.cp/casts.exp: print /x &gd print /x (unsigned long long)&gd^M $32 =3D 0xffffc5c8^M (gdb) PASS: gdb.cp/casts.exp: print /x (unsigned long long)&gd print /x gd_value^M $33 =3D 0xffffffffffffc5c8^M (gdb) PASS: gdb.cp/casts.exp: print /x gd_value print (unsigned long long) &gd =3D=3D gd_value^M $34 =3D false^M (gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd =3D=3D gd_= value ... =20 The gd_value is set by this assignment: ... unsigned long long gd_value =3D (unsigned long long) &gd; ... =20 The problem here is directly casting from a pointer to a non-pointer-si= zed integer. =20 Fix this by adding an intermediate cast to std::uintptr_t. =20 Tested on x86_64-linux with native and target board unix/-m32. Diff: --- gdb/testsuite/gdb.cp/casts.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.cp/casts.cc b/gdb/testsuite/gdb.cp/casts.cc index ea4dc961793..f64d13c26df 100644 --- a/gdb/testsuite/gdb.cp/casts.cc +++ b/gdb/testsuite/gdb.cp/casts.cc @@ -1,3 +1,5 @@ +#include + struct A { int a; @@ -65,7 +67,7 @@ main (int argc, char **argv) LeftRight gd; gd.left =3D 23; gd.right =3D 27; - unsigned long long gd_value =3D (unsigned long long) &gd; + unsigned long long gd_value =3D (unsigned long long) (std::uintptr_t)&gd; unsigned long long r_value =3D (unsigned long long) (Right *) &gd; =20 return 0; /* breakpoint spot: casts.exp: 1 */