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

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


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.

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.

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.

-Eli



More information about the llvm-dev mailing list