[LLVMdev] Do I need to calculate padding by myself to construct a StructType ?

Wei Li limijd at gmail.com
Thu Nov 8 17:22:54 PST 2012


I am using LLVM C++ API to generate IR for some structure data.

For example:

struct mystruct {int a:1; int b:2; unsigned long c} = {{1, 2, 3}};

I read the document and tried the demo cgi, it seems the API requires user
to handle padding and value combination for the initializer by themselves.

Is there any way to create the struct more simply like this:

fields.push_back(Type::getIntNTy(context, 1));
fields.push_back(Type::getIntNTy(context, 2));
fields.push_back(Type::getIntNTy(context, 64));
structTy.setBody(fields, false /* isPacked*/);

It's really tough to do layout work and it's very likely to cause bugs.
Combining the values for the initializer is also not easy.

As my understanding, if I tell llvm API that the struct is not packed, it
should handle padding automatically, right?

Any comments? Any pointer to references is also appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121108/9c011906/attachment.html>


More information about the llvm-dev mailing list