On Sat, Sep 21, 2019 at 2:23 AM Jakub Jelinek <ja...@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  <ja...@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 via email to