public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tom de Vries <vries@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] [gdb/testsuite] Fix gdb.cp/casts.exp with -m32
Date: Sun,  8 May 2022 17:38:18 +0000 (GMT)	[thread overview]
Message-ID: <20220508173818.C9FBB3858D33@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a1aaf801d5f0989ea0857dfd896830570603b523

commit a1aaf801d5f0989ea0857dfd896830570603b523
Author: Tom de Vries <tdevries@suse.de>
Date:   Sun May 8 19:38:13 2022 +0200

    [gdb/testsuite] Fix gdb.cp/casts.exp with -m32
    
    When running test-case gdb.cp/casts.exp with target board unix/-m32, I run
    into:
    ...
    (gdb) print (unsigned long long) &gd == gd_value^M
    $31 = false^M
    (gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd == gd_value
    ...
    
    With some additional printing, we can see in more detail why the comparison
    fails:
    ...
    (gdb) print /x &gd^M
    $31 = 0xffffc5c8^M
    (gdb) PASS: gdb.cp/casts.exp: print /x &gd
    print /x (unsigned long long)&gd^M
    $32 = 0xffffc5c8^M
    (gdb) PASS: gdb.cp/casts.exp: print /x (unsigned long long)&gd
    print /x gd_value^M
    $33 = 0xffffffffffffc5c8^M
    (gdb) PASS: gdb.cp/casts.exp: print /x gd_value
    print (unsigned long long) &gd == gd_value^M
    $34 = false^M
    (gdb) FAIL: gdb.cp/casts.exp: print (unsigned long long) &gd == gd_value
    ...
    
    The gd_value is set by this assignment:
    ...
      unsigned long long gd_value = (unsigned long long) &gd;
    ...
    
    The problem here is directly casting from a pointer to a non-pointer-sized
    integer.
    
    Fix this by adding an intermediate cast to std::uintptr_t.
    
    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 <cstdint>
+
 struct A
 {
   int a;
@@ -65,7 +67,7 @@ main (int argc, char **argv)
   LeftRight gd;
   gd.left = 23;
   gd.right = 27;
-  unsigned long long gd_value = (unsigned long long) &gd;
+  unsigned long long gd_value = (unsigned long long) (std::uintptr_t)&gd;
   unsigned long long r_value = (unsigned long long) (Right *) &gd;
 
   return 0;  /* breakpoint spot: casts.exp: 1 */


                 reply	other threads:[~2022-05-08 17:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220508173818.C9FBB3858D33@sourceware.org \
    --to=vries@sourceware.org \
    --cc=gdb-cvs@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).