public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org, Jonathan Wakely <jwakely@redhat.com>
Subject: Re: [PATCH] c++, v2: Allow indeterminate unsigned char or std::byte in bit_cast - P1272R4
Date: Thu, 2 Dec 2021 21:56:59 +0100	[thread overview]
Message-ID: <20211202205659.GL2646553@tucnak> (raw)
In-Reply-To: <1f03c962-edc6-40ed-0327-76dedfca832c@redhat.com>

On Thu, Dec 02, 2021 at 03:32:58PM -0500, Jason Merrill wrote:
> > So IMHO we need the patch I've posted (with the testcases slightly adjusted
> > not to do those extra copies afterwards for now),
> > and try to deal with the lvalue-to-rvalue conversion of indeterminate later,
> > and once done, perhaps in a copy of those testcases readd those extra copies
> > afterwards and verify it is rejected.
> 
> Makes sense, except:
> 
> > +	      gcc_assert (end == 1 || end == 2);
> 
> This seems to assert that the value representation of a bit-field can't span
> more than two bytes, which is wrong for, say,
> 
> struct A
> {
>   int : 1;
>   unsigned __int128 c : 128; // value representation spans 17 bytes
> };

Sure, for arbitrary bitfields yes.  But, the patch only deals with
unsigned char and std::byte TYPE_MAIN_VARIANT (DECL_BIT_FIELD_TYPE (fld))
bitfields (others don't have the type listed in the standard and so should
error right away, which is done by keeping the mask bits uncleared).

For PCC_BITFIELD_TYPE_MATTERS I think end must be 1 even, if a bit-field
would cross the byte boundary, it would be allocated in the next byte.
But !PCC_BITFIELD_TYPE_MATTERS targets can cross the boundary, but as it
can't be more than BITS_PER_UNIT bits (oversized bitfields are with warning
downsized to the underlying's type precision), it can occupy at most 2
bytes.

	Jakub


  reply	other threads:[~2021-12-02 20:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 16:31 [PATCH] c++: " Jakub Jelinek
2021-11-30  3:25 ` Jason Merrill
2021-11-30 12:17   ` [PATCH] c++, v2: " Jakub Jelinek
2021-11-30 20:19     ` Jason Merrill
2021-12-01  9:46       ` Jakub Jelinek
2021-12-02 20:32         ` Jason Merrill
2021-12-02 20:56           ` Jakub Jelinek [this message]
2021-12-03 18:56             ` Jason Merrill
2021-12-04 10:12               ` Jakub Jelinek

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=20211202205659.GL2646553@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=jwakely@redhat.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).