Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class inherit from "enable_shared_from_this", incorrect reordering will occur #38

Open
HealthyChina opened this issue Mar 6, 2023 · 2 comments

Comments

@HealthyChina
Copy link

Example:

#include <iostream>
using namespace std;

class TTT
{
public:
    int a; // 4
    char b; // 4
};

class FFF
{
public:
    int c; // 4
};

class async_service_helper : public enable_shared_from_this<async_service_helper>
{
    virtual ~async_service_helper() { cout << "test" << endl; }

public:

    int i1;
    unsigned int i2;
    TTT* ptr_t;
    FFF* ptr_f;
};
@acmel
Copy link
Owner

acmel commented Mar 6, 2023

Can you describe the incorrect reordering taking place? Consider cut and pasting here the output of the tool that you think is erroneous.

@HealthyChina
Copy link
Author

HealthyChina commented Mar 11, 2023

----> async_service_helper ---->
/* Original struct: */
class async_service_helper : public enable_shared_from_this<async_service_helper> {

        /* XXX 8 bytes hole, try to pack */
public:


        /* class enable_shared_from_this<async_service_helper> <ancestor>; */ /*     8    16 */

        /* XXX 65512 bytes hole, try to pack */
        void async_service_helper(class async_service_helper *, const class async_service_helper  &);

        void async_service_helper(class async_service_helper *);


        int ()(void) * *           _vptr.async_service_helper; /*     0     8 */

        /* XXX 16 bytes hole, try to pack */
        virtual void ~async_service_helper(class async_service_helper *, int);


        class FFF *                ptr_f;                /*    24     8 */
        int                        i1;                   /*    32     4 */

        /* XXX 4 bytes hole, try to pack */

        class TTT *                ptr_t;                /*    40     8 */
        class GGG *                ptr_g;                /*    48     8 */
        unsigned int               i2;                   /*    56     4 */
        int Test(class async_service_helper *);


        /* size: 64, cachelines: 1, members: 7 */
        /* sum members: 40, holes: 4, sum holes: 65540 */
        /* padding: 4 */

        /* BRAIN FART ALERT! 64 bytes != 40 (member bytes) + 0 (member bits) + 65540 (byte holes) + 0 (bit holes), diff = -524160 bits */
};/* Moving 'i1' from after 'ptr_f' to after '_vptr.async_service_helper' */
/* Moving 'i2' from after 'ptr_g' to after 'i1' */
/* Moving 'ptr_g' from after 'ptr_t' to after 'i2' */
/* Final reorganized struct: */
class async_service_helper : public enable_shared_from_this<async_service_helper> {

        /* XXX 8 bytes hole, try to pack */
public:


        /* class enable_shared_from_this<async_service_helper> <ancestor>; */ /*     8    16 */

        /* XXX 65512 bytes hole, try to pack */

        int ()(void) * *           _vptr.async_service_helper; /*     0     8 */
        int                        i1;                   /*     8     4 */
        unsigned int               i2;                   /*    12     4 */
        class GGG *                ptr_g;                /*    16     8 */
        class FFF *                ptr_f;                /*    24     8 */
        class TTT *                ptr_t;                /*    32     8 */

        /* size: 40, cachelines: 1, members: 7 */
        /* sum members: 40, holes: 2, sum holes: 65520 */
        /* last cacheline: 40 bytes */

        /* BRAIN FART ALERT! 40 bytes != 40 (member bytes) + 0 (member bits) + 65520 (byte holes) + 0 (bit holes), diff = -524160 bits */
};
   /* saved 24 bytes! */
<---- async_service_helper <----

Reordering shouldn't start at 0, because the previous one is already occupied.(/* class enable_shared_from_this<async_service_helper> ; / / 8 16 */)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants