public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: David Allsopp <David.Allsopp@cl.cam.ac.uk>
To: "cygwin-patches@cygwin.com" <cygwin-patches@cygwin.com>
Subject: RE: [PATCH] Fix incorrect sign-extension of pointer in 32-bit acl __to_entry
Date: Fri, 10 Jul 2020 18:31:13 +0000	[thread overview]
Message-ID: <9adcf190b395491da501825821366f52@metastack.com> (raw)
In-Reply-To: <20200710155858.GG514059@calimero.vinschen.de>

Corinna Vinschen wrote:
> On Jul 10 15:22, David Allsopp via Cygwin-patches wrote:
> > Corinna Vinschen wrote:
> > > On Jul  9 20:30, David Allsopp via Cygwin-patches wrote:
> > > > I have some code where the acl_t returned by get_file_acl is
> > > > allocated at 0x80038248. As a result the acl_entry_t generated by
> > > > acl_get_entry has an "index" of -1, since the pointer was sign-
> extended to 64-bits.
> > > >
> > > > My fix is trivial and simply casts the pointer to uintptr_t first.
> > >
> > > Pushed.  I still don't quite understand what the compiler is
> > > thinking there, sign-extending a pointer when casted to an unsigend
> > > int type, but your patch works, so all is well, I guess.
> >
> > Thank you - it is indeed hard to imagine when you'd ever want that
> behaviour!
> 
> I wonder if this is a bug in x86 gcc... Jon?

I put it to our C gurus in the OCaml team - one (who has also written a formally verified C compiler which on purpose 0-extends in this case) observed that GCC does the same for ARM32 and another (who has occasionally delighted in abusing language memory models to concoct highly bizarre, but legal, abuses of undefined behaviour) found https://gcc.gnu.org/onlinedocs/gcc/Arrays-and-pointers-implementation.html... although the Git history for GCC makes it fairly clear that this behaviour is retrospectively documented[1][2]!


David


[1] https://github.com/gcc-mirror/gcc/commit/cbf4c36fa373
[2] https://github.com/gcc-mirror/gcc/commit/58f4de4f271c

  reply	other threads:[~2020-07-10 18:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-09 19:30 David Allsopp
2020-07-10  8:32 ` Corinna Vinschen
2020-07-10 15:22   ` David Allsopp
2020-07-10 15:58     ` Corinna Vinschen
2020-07-10 18:31       ` David Allsopp [this message]
2020-07-13  7:18         ` Corinna Vinschen

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=9adcf190b395491da501825821366f52@metastack.com \
    --to=david.allsopp@cl.cam.ac.uk \
    --cc=cygwin-patches@cygwin.com \
    /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).