public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: [C++ PATCH 4/4] PR c++/30277 - int-width bit-field promotion.
Date: Sat, 21 Sep 2019 21:51:00 -0000	[thread overview]
Message-ID: <CADzB+2kcaajp_mh_DVVxnPZ-ci=uq+F6zatDJrZ3SiR5nG24Rg@mail.gmail.com> (raw)
In-Reply-To: <20190921062305.GD15914@tucnak>

On Sat, Sep 21, 2019 at 2:23 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Mon, Sep 16, 2019 at 12:33:28AM -0400, Jason Merrill wrote:
> > Here, if cp_perform_integral_promotions saw that the TREE_TYPE of a
> > bit-field reference was the same as the type it promotes to, it didn't do
> > anything.  But then decay_conversion saw that the bit-field reference was
> > unchanged, and converted it to its declared type.  So I needed to add
> > something to make it clear that promotion has been done.  But then the 33819
> > change caused trouble by looking through the NOP_EXPR I just added.  This
> > was the wrong fix for that bug; I've now fixed that better by recognizing in
> > cp_perform_integral_promotions that we won't promote a bit-field larger than
> > 32 bits, so we should use the declared type.
> >
> > Tested x86_64-pc-linux-gnu, applying to trunk.
> >
> >       PR c++/33819 - long bit-field promotion.
> >       * typeck.c (cp_perform_integral_promotions): Handle large bit-fields
> >       properly.  Handle 32-bit non-int bit-fields properly.
> >       (is_bitfield_expr_with_lowered_type): Don't look through NOP_EXPR.
>
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/expr/bitfield14.C
> > @@ -0,0 +1,17 @@
> > +// PR c++/30277
> > +// { dg-do compile { target c++11 } }
> > +
> > +struct S
> > +{
> > +  signed long l: 32;
> > +};
> > +
> > +void foo(long) = delete;
> > +void foo(int) {}
> > +
> > +int main()
> > +{
> > +  S x = {1};
> > +  foo(x.l+0);
> > +  return 0;
> > +}
>
> This testcase fails on all targets where int and long have the same
> precision.  Is that a bug on the compiler side, or should the testcase just
> use a type with a larger precision than int (i.e. long long), like following
> (tested on x86_64-linux and i686-linux):

It's a testcase bug.

> 2019-09-21  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/30277
>         * g++.dg/expr/bitfield14.C (struct S): Use signed long long instead
>         of signed long.
>         (foo): Use long long instead of long.

OK, thanks.

Jason

  reply	other threads:[~2019-09-21 21:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16  4:33 [C++ PATCH 1/4] Handle location wrappers better in warn_logical_operator Jason Merrill
2019-09-16  4:33 ` [C++ PATCH 4/4] PR c++/30277 - int-width bit-field promotion Jason Merrill
2019-09-21  6:23   ` Jakub Jelinek
2019-09-21 21:51     ` Jason Merrill [this message]
2019-09-16  4:33 ` [C++ PATCH 3/4] PR c++/82165 - enum bitfields and operator overloading Jason Merrill
2019-09-16  4:33 ` [C++ PATCH 2/4] Fix conversions for built-in operator overloading candidates Jason Merrill
2019-09-17 14:07   ` Andreas Schwab
2019-09-17 14:19     ` Iain Sandoe
2019-09-19  0:19   ` JiangNing OS
2019-09-19 19:43     ` Jason Merrill
2019-09-19 20:11       ` Jason Merrill
2019-09-19 20:28         ` Marek Polacek
2019-11-05 23:53       ` Jason Merrill

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='CADzB+2kcaajp_mh_DVVxnPZ-ci=uq+F6zatDJrZ3SiR5nG24Rg@mail.gmail.com' \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@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).