[cfe-dev] [LLVMdev] Mapping field names to GEP indices in clang-compiled C

Eli Friedman eli.friedman at gmail.com
Mon May 11 16:56:29 PDT 2009


On Mon, May 11, 2009 at 2:17 PM, Jeffrey Yasskin <jyasskin at google.com> wrote:
>> clang's current behavior here is a bug, but it's a low priority to fix
>> because the generated IR isn't incorrect, just somewhat difficult to
>> read.
>
> Oh, good. Is there a bug number for that? I'd assumed that it was
> intentional to give clang more control over struct layout, but if it's
> accidental I'll look forward to a fix. If I get annoyed enough at it,
> I may even try to fix it myself. Do you have any pointers to code I
> should look at to fix it?

I don't think there's a bug filed.  The relevant code is
RecordOrganizer::layoutStructFields in lib/CodeGen/CodeGenTypes.cpp.

If I recall correctly, I originally wrote the code in question.  I
wanted to make the first implementation as simple as possible, and
therefore I only wrote the general case.  The way to fix this is
basically to add detection for structs where the amount of padding
LLVM would insert is never more than the necessary amount, and use an
unpacked struct in those cases.

-Eli



More information about the cfe-dev mailing list