[llvm-dev] Struct padding

Hongbin Zheng via llvm-dev llvm-dev at lists.llvm.org
Thu May 18 00:51:10 PDT 2017


Hi Jonas,

Thanks a lot.
In an LLVM pass, how can I check the related information? will clang emit
some metadata table?

Thanks
Hongbin

On Thu, May 18, 2017 at 12:47 AM, Jonas Devlieghere <jonas at devlieghere.com>
wrote:

> Hi Hongbin,
>
> You can pass `-Wpadded` to clang. For your particular example it will
> print something along the lines of
>
> ```
> warning: padding struct 'foo1' with 7 bytes to align 'x' [-Wpadded]
>     long x;
> ```
>
> Jonas
>
> On Thu, May 18, 2017 at 9:15 AM, Hongbin Zheng via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hi,
>>
>> I am wondering how I can tell whether a field of a struct is introduced
>> by padding or not.
>>
>> For example, if I have a struct:
>>
>> struct foo1 {
>>     char *p;     /* 8 bytes */
>>     char c;      /* 1 byte
>>     long x;      /* 8 bytes */
>> };
>>
>> clang may generate:
>>
>> struct foo1 {
>>     char *p;     /* 8 bytes */
>>     char c;      /* 1 byte
>>     char pad[7]; /* 7 bytes */
>>     long x;      /* 8 bytes */
>> };
>>
>> Is there any way that I can tell the "pad" array is generated by padding?
>>
>> Thanks a lot
>> Hongbin
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170518/081efcb9/attachment.html>


More information about the llvm-dev mailing list