[cfe-dev] Detection of poor data layout / packing.

Ólafur Waage olafurw at gmail.com
Mon Sep 9 18:48:13 PDT 2013


Thanks for the reply.

The flag is -Wpadded and there seems to be very little information about it.

I tried it with a few tests.

struct Test
{
    bool a;
    int b;
};

Gives the warning

"test.cpp:6:9: warning: padding struct 'Test' with 3 bytes to align 'b'
[-Wpadded]"

And it also spots

struct Test
{
    int b;
    bool a;
};

struct Test2
{
    Test t;
    int a;
};

With the warning.

"test.cpp:3:8: warning: padding size of 'Test' with 3 bytes to alignment
boundary"

And it seems to work just fine. Need to look better into this, if it's
catching all of the cases.

Cheers!



On Sat, Sep 7, 2013 at 9:04 PM, Sean Silva <silvas at purdue.edu> wrote:

> Clang's -Wpadding may be sort of like what you want.
>
> -- Sean Silva
>
>
> On Sat, Sep 7, 2013 at 3:27 PM, Ólafur Waage <olafurw at gmail.com> wrote:
>
>> Hey,
>>
>> I asked about this a while back but got no answers. And after seeing the
>> GN talks and specially also after watching Andrei talking about data layout
>> I'm tempted to ask again.
>>
>> Are there any tools within clang/llvm that detect poor data packing in
>> classes?
>>
>> I saw that there exist some flags that can print out the current data
>> structure and the memory offset of each member variable. But it seemed not
>> to work that well given anything else outside of some testing code and
>> trying to parse it seemed to be hard (but not impossible)
>>
>> Would it make sense to try to have a tool or in some way emit the
>> structure and point out places where packing could be improved? If it
>> would, and no tool exists, I would be interested in helping out or doing
>> something on my own.
>>
>> Cheers,
>> Olafur Waage
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130910/fd71ea94/attachment.html>


More information about the cfe-dev mailing list