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

Jeffrey Yasskin jyasskin at google.com
Mon May 11 14:17:25 PDT 2009


On Mon, May 11, 2009 at 11:56 AM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Mon, May 11, 2009 at 10:56 AM, Jeffrey Yasskin <jyasskin at google.com> wrote:
>> Is there a way to get clang to emit a C++-readable mapping from field
>> names to GEP offsets? Or some other way to avoid special-casing these
>> offsets for each architecture? If not, what would be the easiest way
>> to add such an ability?
>
> First-off, this sort of question is more appropriate for cfe-dev;
> please direct any follow-up questions there.

Sorry for the mis-directed email.

> 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?

> The only completely reliable solution I can think of is generating
> something like "int Foo_offsets[] = { offsetof(struct Foo, x),
> offsetof(struct Foo, y)};", then use some bitcasting to do the
> arithmetic.

Yeah, that's a good point. I'd lose LLVM's type checking but at least
the code would work.



More information about the cfe-dev mailing list