[Bug c++/87137] New: [8 Regression] Non-virtual member function increases struct size

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] New: [8 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

            Bug ID: 87137
           Summary: [8 Regression] Non-virtual member function increases
                    struct size
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manisandro at gmail dot com
  Target Milestone: ---

With gcc-8.0.0 onwards, specifically commit
ab87ee8f509c0b600102195704105d4d98ec59d9, the following test case fails to
compile using either i686-w64-mingw32-g++ or x86_64-w64-mingw32-g++ (but
compiles normally using the native x86_64-linux-g++):

--- test.cpp ---

template <typename ToCheck, unsigned ExpectedSize, unsigned RealSize =
sizeof(ToCheck)>
void check_size() {
  static_assert(ExpectedSize == RealSize, "Size is off!");
}

struct Foo {
    unsigned u1 : 5;
    unsigned u2 : 5;
    unsigned u3 : 3;
    unsigned u4 : 3;
    unsigned u5 : 4;
    unsigned u6 : 2;
    unsigned u7 : 3;
    unsigned u8 : 2;
    unsigned u9 : 1;

    unsigned u10 : 3;
    // 31 bits
    unsigned u11 : 2;
    unsigned u12 : 2;
    unsigned u13 : 2;

    unsigned u14 : 6;
    unsigned u15 : 7;
    unsigned u16 : 1;
    unsigned u17 : 1;
    unsigned u18 : 1;
    unsigned u19 : 1;
    unsigned u20 : 1;

    bool bar() const { return false; }
private:
    unsigned u21 : 1;
    unsigned u22 : 1;
    unsigned u23 : 1;
    unsigned u24 : 1;
    // 59 bits
};

int main(int argc, char* argv[]) {
    check_size<Foo, 8>();
    return 0;
}

-----

$ x86_64-w64-mingw32-g++ test.cpp -o test.exe
test.cpp: In instantiation of 'void check_size() [with ToCheck = Foo; unsigned
int ExpectedSize = 8; unsigned int RealSize = 12]':
test.cpp:41:24:   required from here
test.cpp:3:30: error: static assertion failed: Size is off!
   static_assert(ExpectedSize == RealSize, "Size is off!");


Notice the presence of the bar member function. Without the member function,
sizeof(Foo) = 8 as expected, but with the member function, sizeof(Foo) = 12.
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

Sandro Mani <manisandro at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |i686-w64-mingw32,
                   |                            |x86_64-w64-mingw32
                 CC|                            |nathan at acm dot org

--- Comment #1 from Sandro Mani <manisandro at gmail dot com> ---
CC [hidden email] as author of ab87ee8f509c0b600102195704105d4d98ec59d9
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

Nathan Sidwell <nathan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nathan at gcc dot gnu.org

--- Comment #2 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
What changelog does that has refer to? (I don;t use the git repo)
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-08-29
      Known to work|                            |7.3.0
            Summary|[8 Regression] Non-virtual  |[8/9 Regression]
                   |member function increases   |Non-virtual member function
                   |struct size                 |increases struct size
     Ever confirmed|0                           |1
      Known to fail|                            |9.0

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That's r250413

Confirmed
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ABI, wrong-code
   Target Milestone|---                         |8.3
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

Nathan Sidwell <nathan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |nathan at gcc dot gnu.org
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #5 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
what should the layout of the following be?
struct Foo {
  unsigned one : 24;
  static int var;
  unsigned two : 4;
};

is this size 8 or 4?
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #6 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Created attachment 44623
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44623&action=edit
patch

This patch appears to fix the problem  It'd be good to (a) confirms it also
passes on MS's compiler
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #7 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Created attachment 44624
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44624&action=edit
this is the testcase
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It compiles successfully with MSVC https://godbolt.org/z/Cw-yiW
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #9 from Liu Hao <lh_mouse at 126 dot com> ---
(In reply to Nathan Sidwell from comment #6)
> Created attachment 44623 [details]
> patch
>
> This patch appears to fix the problem  It'd be good to (a) confirms it also
> passes on MS's compiler

With this patch applied, GCC 8.2.1 accepts the testcase, as well as Microsoft
CL 19.15.26726 .
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #10 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
gcc-8 patch posted https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01900.html
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #11 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Author: nathan
Date: Wed Sep  5 10:04:58 2018
New Revision: 264119

URL: https://gcc.gnu.org/viewcvs?rev=264119&root=gcc&view=rev
Log:
PR c++/87137] GCC-8 Fix

https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01966.html
        PR c++/87137
        * stor-layout.c (place_field): Scan forwards to check last
        bitfield when ms_bitfield_placement is in effect.
        gcc/testsuite/
        * g++.dg/abi/pr87137.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/abi/pr87137.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/stor-layout.c
    trunk/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #12 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Fixed trunk r264119
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #13 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Fixed gcc-8 r264123.

changes.html remains to do
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

--- Comment #14 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
Author: nathan
Date: Wed Sep  5 10:42:59 2018
New Revision: 264123

URL: https://gcc.gnu.org/viewcvs?rev=264123&root=gcc&view=rev
Log:
[PR c++/87137] GCC-8 Fix

https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01966.html
        PR c++/87137
        * stor-layout.c (place_field): Scan forwards to check last
        bitfield when ms_bitfield_placement is in effect.
        gcc/testsuite/
        * g++.dg/abi/pr87137.C: New.

Added:
    branches/gcc-8-branch/gcc/testsuite/g++.dg/abi/pr87137.C
Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/stor-layout.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug c++/87137] [8/9 Regression] Non-virtual member function increases struct size

asolokha at gmx dot com
In reply to this post by asolokha at gmx dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87137

Nathan Sidwell <nathan at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #15 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
I forgot to mark this fixed.