public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <jeffreyalaw@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>,
	Richard Biener <rguenther@suse.de>,
	"Joseph S. Myers" <josmyers@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] pretty-print: Fix up ptrdiff handling for %tu, %to, %tx
Date: Tue, 13 Feb 2024 09:11:42 -0700	[thread overview]
Message-ID: <41b30348-39cb-47cd-91c9-2e21b0d509ea@gmail.com> (raw)
In-Reply-To: <ZcsmdzB5Z0cVB+0B@tucnak>



On 2/13/24 01:21, Jakub Jelinek wrote:
> Hi!
> 
> This is IMHO more of a theoretical case, I believe my current code
> doesn't handle %tu or %to or %tx correctly if ptrdiff_t is not one of
> int, long int or long long int.  For size_t and %zd or %zi I'm
> using va_arg (whatever, ssize_t) and hope that ssize_t is the signed
> type corresponding to size_t which C99 talks about.
> For ptrdiff_t there is no type for unsigned type corresponding to
> ptrdiff_t and I'm not aware of a portable way on the host to get
> such a type (the fmt tests use hacks like
> #define signed /* Type might or might not have explicit 'signed'.  */
> typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t;
> #undef signed
> but that only works with compilers which predefine __PTRDIFF_TYPE__),
> std::make_unsigned<ptrdiff_t> I believe only works reliably if
> ptrdiff_t is one of char, signed char, short, int, long or long long,
> but won't work e.g. for __int20__ or whatever other weird ptrdiff_t
> the host might have.
> 
> The following patch assumes host is two's complement (I think we
> rely on it pretty much everywhere anyway) and prints unsigned type
> corresponding to ptrdiff_t as unsigned long long printing of
> ptrdiff_t value masked with 2ULL * PTRDIFF_MAX + 1.  So the only
> actual limitation is that it doesn't support ptrdiff_t wider than
> long long int.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2024-02-13  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* pretty-print.cc (PTRDIFF_MAX): Define if not yet defined.
> 	(pp_integer_with_precision): For unsigned ptrdiff_t printing
> 	with u, o or x print ptrdiff_t argument converted to
> 	unsigned long long and masked with 2ULL * PTRDIFF_MAX + 1.
> 
> 	* error.cc (error_print): For u printing of ptrdiff_t,
> 	print ptrdiff_t argument converted to unsigned long long and
> 	masked with 2ULL * PTRDIFF_MAX + 1.
OK
jeff

      reply	other threads:[~2024-02-13 16:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13  8:21 Jakub Jelinek
2024-02-13 16:11 ` Jeff Law [this message]

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=41b30348-39cb-47cd-91c9-2e21b0d509ea@gmail.com \
    --to=jeffreyalaw@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=josmyers@redhat.com \
    --cc=rguenther@suse.de \
    /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).