This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH 4/4] PR c++/30277 - int-width bit-field promotion.
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 21 Sep 2019 17:51:14 -0400
- Subject: Re: [C++ PATCH 4/4] PR c++/30277 - int-width bit-field promotion.
- References: <20190916043328.3739-1-jason@redhat.com> <20190916043328.3739-4-jason@redhat.com> <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